@hongmaple0820/scale-engine 0.25.0 → 0.26.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.
Files changed (143) hide show
  1. package/LICENSE +15 -15
  2. package/README.en.md +368 -346
  3. package/README.md +548 -529
  4. package/dist/adapters/AiderAdapter.js +52 -52
  5. package/dist/adapters/AntigravityAdapter.d.ts +4 -0
  6. package/dist/adapters/AntigravityAdapter.js +21 -0
  7. package/dist/adapters/AntigravityAdapter.js.map +1 -0
  8. package/dist/adapters/ClaudeCodeAdapter.d.ts +4 -1
  9. package/dist/adapters/ClaudeCodeAdapter.js +34 -34
  10. package/dist/adapters/ClaudeCodeAdapter.js.map +1 -1
  11. package/dist/adapters/ClineAdapter.d.ts +4 -0
  12. package/dist/adapters/ClineAdapter.js +20 -0
  13. package/dist/adapters/ClineAdapter.js.map +1 -0
  14. package/dist/adapters/CodexAdapter.js +28 -28
  15. package/dist/adapters/CursorAdapter.js +26 -26
  16. package/dist/adapters/DeepSeekTuiAdapter.js +97 -97
  17. package/dist/adapters/DoubaoAdapter.js +33 -33
  18. package/dist/adapters/GeminiAdapter.js +26 -26
  19. package/dist/adapters/GenericProjectAgentAdapter.d.ts +29 -0
  20. package/dist/adapters/GenericProjectAgentAdapter.js +204 -0
  21. package/dist/adapters/GenericProjectAgentAdapter.js.map +1 -0
  22. package/dist/adapters/HermesAdapter.js +26 -26
  23. package/dist/adapters/JCodeAdapter.d.ts +4 -0
  24. package/dist/adapters/JCodeAdapter.js +19 -0
  25. package/dist/adapters/JCodeAdapter.js.map +1 -0
  26. package/dist/adapters/KiloCodeAdapter.d.ts +4 -0
  27. package/dist/adapters/KiloCodeAdapter.js +20 -0
  28. package/dist/adapters/KiloCodeAdapter.js.map +1 -0
  29. package/dist/adapters/KimiAdapter.js +32 -32
  30. package/dist/adapters/KiroAdapter.js +26 -26
  31. package/dist/adapters/OpenClawAdapter.js +26 -26
  32. package/dist/adapters/OpenCodeAdapter.js +26 -26
  33. package/dist/adapters/QCoderAdapter.js +26 -26
  34. package/dist/adapters/QoderAdapter.d.ts +4 -0
  35. package/dist/adapters/QoderAdapter.js +21 -0
  36. package/dist/adapters/QoderAdapter.js.map +1 -0
  37. package/dist/adapters/TraeAdapter.js +26 -26
  38. package/dist/adapters/VSCAdapter.js +26 -26
  39. package/dist/adapters/WindsurfAdapter.js +32 -32
  40. package/dist/adapters/WorkBuddyAdapter.js +26 -26
  41. package/dist/adapters/index.d.ts +5 -0
  42. package/dist/adapters/index.js +15 -0
  43. package/dist/adapters/index.js.map +1 -1
  44. package/dist/api/cli.js +133 -47
  45. package/dist/api/cli.js.map +1 -1
  46. package/dist/api/doctor.js +10 -3
  47. package/dist/api/doctor.js.map +1 -1
  48. package/dist/api/quickstart.js +7 -1
  49. package/dist/api/quickstart.js.map +1 -1
  50. package/dist/artifact/sqliteStore.js +89 -89
  51. package/dist/artifact/types.d.ts +1 -1
  52. package/dist/cli/phaseCommands.js +45 -45
  53. package/dist/context/AntiPatternRegistry.js +20 -20
  54. package/dist/context/ContextBuilder.js +155 -155
  55. package/dist/evolution/EvolutionEngine.js +31 -31
  56. package/dist/evolution/EvolutionEvaluator.d.ts +2 -0
  57. package/dist/evolution/EvolutionEvaluator.js +7 -1
  58. package/dist/evolution/EvolutionEvaluator.js.map +1 -1
  59. package/dist/fsm/FSMAgentBridge.js +11 -11
  60. package/dist/hooks/HookGeneratorEnhanced.js +218 -218
  61. package/dist/index.d.ts +1 -1
  62. package/dist/index.js +2 -2
  63. package/dist/index.js.map +1 -1
  64. package/dist/knowledge/SQLiteKnowledgeBase.js +28 -28
  65. package/dist/memory/MemoryBrain.js +52 -52
  66. package/dist/output/GovernanceDashboard.js +44 -44
  67. package/dist/output/HTMLArtifactLayer.js +31 -31
  68. package/dist/prompts/VibeTemplateGallery.js +121 -121
  69. package/dist/skills/SkillDiscovery.js +12 -1
  70. package/dist/skills/SkillDiscovery.js.map +1 -1
  71. package/dist/skills/routing/SkillPlanner.js +40 -40
  72. package/dist/workflow/EngineeringStandards.js +62 -62
  73. package/dist/workflow/GovernanceTemplatePacks.d.ts +1 -1
  74. package/dist/workflow/GovernanceTemplatePacks.js +1990 -162
  75. package/dist/workflow/GovernanceTemplatePacks.js.map +1 -1
  76. package/dist/workflow/GovernanceTemplates.d.ts +2 -0
  77. package/dist/workflow/GovernanceTemplates.js +1012 -1001
  78. package/dist/workflow/GovernanceTemplates.js.map +1 -1
  79. package/dist/workflow/ResourceGovernance.js +16 -16
  80. package/dist/workflow/TaskArtifactScaffolder.js +10 -10
  81. package/dist/workflow/UpgradeManager.d.ts +3 -2
  82. package/dist/workflow/UpgradeManager.js +134 -49
  83. package/dist/workflow/UpgradeManager.js.map +1 -1
  84. package/dist/workflow/WorkspaceTopology.js +18 -15
  85. package/dist/workflow/WorkspaceTopology.js.map +1 -1
  86. package/docs/ACTIVE_SECURITY_VISUAL_GATES.md +87 -87
  87. package/docs/BACKGROUND_HUNTER.md +62 -62
  88. package/docs/CODE_INTELLIGENCE.md +138 -138
  89. package/docs/CONTEXT_BUDGET.md +113 -113
  90. package/docs/DEPENDENCY_AUDIT.md +89 -89
  91. package/docs/EVOLUTION_SHADOW_MODE.md +63 -63
  92. package/docs/EXTERNAL_REFERENCES.md +63 -58
  93. package/docs/GITLAB_FLOW.md +125 -125
  94. package/docs/GOVERNANCE_DASHBOARD.md +85 -85
  95. package/docs/MEMORY_BRAIN.md +104 -104
  96. package/docs/MEMORY_FABRIC.md +134 -134
  97. package/docs/README.md +101 -92
  98. package/docs/RUNTIME_EVIDENCE.md +101 -101
  99. package/docs/SKILL-REPOSITORY.md +57 -57
  100. package/docs/SKILL_RADAR.md +122 -122
  101. package/docs/THIRD_PARTY_SKILLS.md +57 -57
  102. package/docs/WORKFLOW_EVAL.md +151 -151
  103. package/docs/guides/DEVELOPMENT_WORKFLOW.md +80 -0
  104. package/docs/guides/GETTING_STARTED.md +50 -0
  105. package/docs/start/README.md +78 -72
  106. package/docs/start/agent-governance-demo.md +107 -107
  107. package/docs/start/quickstart.md +137 -127
  108. package/docs/start/workflow-upgrade.md +32 -8
  109. package/docs/workflow/README.md +67 -0
  110. package/docs/workflow/node-library.md +52 -0
  111. package/docs/workflow/templates/api-contract.md +29 -0
  112. package/docs/workflow/templates/architecture-review.md +23 -0
  113. package/docs/workflow/templates/db-change-plan.md +20 -0
  114. package/docs/workflow/templates/docs-impact.md +17 -0
  115. package/docs/workflow/templates/e2e-plan.md +20 -0
  116. package/docs/workflow/templates/explore.md +16 -0
  117. package/docs/workflow/templates/github-actions-scale-preflight.yml +32 -0
  118. package/docs/workflow/templates/mini-prd.md +16 -0
  119. package/docs/workflow/templates/plan.md +37 -0
  120. package/docs/workflow/templates/pre-push-scale-preflight.sh +8 -0
  121. package/docs/workflow/templates/product-smoke.md +61 -0
  122. package/docs/workflow/templates/reality-check.md +28 -0
  123. package/docs/workflow/templates/resource-cleanup.md +17 -0
  124. package/docs/workflow/templates/resource-impact.md +25 -0
  125. package/docs/workflow/templates/review.md +12 -0
  126. package/docs/workflow/templates/runtime.md +23 -0
  127. package/docs/workflow/templates/security-review.md +26 -0
  128. package/docs/workflow/templates/skill-evidence.md +33 -0
  129. package/docs/workflow/templates/skill-plan.md +39 -0
  130. package/docs/workflow/templates/spec.md +17 -0
  131. package/docs/workflow/templates/standards-impact.md +28 -0
  132. package/docs/workflow/templates/summary.md +16 -0
  133. package/docs/workflow/templates/tasks.md +8 -0
  134. package/docs/workflow/templates/ui-spec.md +29 -0
  135. package/docs/workflow/templates/verification.md +20 -0
  136. package/docs/workflow/templates/visual-review.md +20 -0
  137. package/examples/demo-projects/agent-governance-demo/CONTEXT.md +14 -14
  138. package/examples/demo-projects/agent-governance-demo/README.md +48 -48
  139. package/examples/demo-projects/agent-governance-demo/docs/CONTEXT-MAP.md +14 -14
  140. package/examples/demo-projects/agent-governance-demo/package.json +22 -21
  141. package/examples/demo-projects/agent-governance-demo/src/oauth-state.ts +39 -39
  142. package/examples/demo-projects/agent-governance-demo/tests/oauth-state.test.ts +52 -52
  143. package/package.json +88 -78
@@ -1,7 +1,7 @@
1
1
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
2
2
  import { basename, join } from 'node:path';
3
3
  import { skillRoutingPolicyTemplate } from '../skills/routing/SkillPolicy.js';
4
- import { readGovernanceLock, writeGovernanceLock } from './GovernanceLock.js';
4
+ import { computeGovernanceDrift, readGovernanceLock, writeGovernanceLock } from './GovernanceLock.js';
5
5
  import { resolveGovernanceTemplatePack, } from './GovernanceTemplatePacks.js';
6
6
  import { engineeringStandardsBaselineTemplate, engineeringStandardsPolicyTemplate, frameworksCatalogTemplate, } from './EngineeringStandards.js';
7
7
  import { resourceManifestTemplate, resourcePolicyTemplate } from './ResourceGovernance.js';
@@ -14,55 +14,61 @@ export function writeGovernanceTemplates(projectDir = process.cwd(), options = {
14
14
  const packMode = pack.modeDefaults[mode];
15
15
  const services = options.services ?? pack.defaultServices ?? detectRootServices(projectDir, pack.id);
16
16
  const exclude = options.exclude ?? pack.exclude ?? ['node_modules', 'dist', 'tmp', 'vendor'];
17
- const result = { created: [], skipped: [] };
17
+ const result = { created: [], updated: [], skipped: [] };
18
18
  const lockFiles = new Map();
19
+ const packOverrides = new Set(pack.generatedFiles.map(file => file.path));
20
+ const overwritePaths = options.overwriteManaged
21
+ ? new Set(computeGovernanceDrift(projectDir).clean.map(entry => entry.path))
22
+ : new Set();
19
23
  for (const file of readGovernanceLock(projectDir)?.files ?? []) {
20
24
  lockFiles.set(file.path, file);
21
25
  }
22
- writeTracked(result, lockFiles, projectDir, 'docs/workflow/README.md', workflowReadme(projectName, mode, pack.id));
23
- writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/explore.md', governanceTemplateContent('explore.md'));
24
- writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/mini-prd.md', governanceTemplateContent('mini-prd.md'));
25
- writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/skill-plan.md', governanceTemplateContent('skill-plan.md'));
26
- writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/skill-evidence.md', governanceTemplateContent('skill-evidence.md'));
27
- writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/runtime.md', governanceTemplateContent('runtime.md'));
28
- writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/reality-check.md', governanceTemplateContent('reality-check.md'));
29
- writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/resource-cleanup.md', governanceTemplateContent('resource-cleanup.md'));
30
- writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/ui-spec.md', governanceTemplateContent('ui-spec.md'));
31
- writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/visual-review.md', governanceTemplateContent('visual-review.md'));
32
- writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/api-contract.md', governanceTemplateContent('api-contract.md'));
33
- writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/docs-impact.md', governanceTemplateContent('docs-impact.md'));
34
- writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/resource-impact.md', governanceTemplateContent('resource-impact.md'));
35
- writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/standards-impact.md', governanceTemplateContent('standards-impact.md'));
36
- writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/architecture-review.md', governanceTemplateContent('architecture-review.md'));
37
- writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/security-review.md', governanceTemplateContent('security-review.md'));
38
- writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/db-change-plan.md', governanceTemplateContent('db-change-plan.md'));
39
- writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/e2e-plan.md', governanceTemplateContent('e2e-plan.md'));
40
- writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/product-smoke.md', governanceTemplateContent('product-smoke.md'));
41
- writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/plan.md', governanceTemplateContent('plan.md'));
42
- writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/verification.md', governanceTemplateContent('verification.md'));
43
- writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/review.md', governanceTemplateContent('review.md'));
44
- writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/summary.md', governanceTemplateContent('summary.md'));
45
- writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/github-actions-scale-preflight.yml', githubActionsPreflightTemplate());
46
- writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/pre-push-scale-preflight.sh', prePushPreflightTemplate());
47
- writeTracked(result, lockFiles, projectDir, 'docs/worklog/metrics.md', metricsTemplate());
48
- writeTracked(result, lockFiles, projectDir, 'scripts/qa/product-smoke.ps1', productSmokePowerShellScript());
49
- writeTracked(result, lockFiles, projectDir, 'scripts/qa/product-smoke.sh', productSmokeShellScript());
26
+ if (!packOverrides.has('docs/workflow/README.md')) {
27
+ writeTracked(result, lockFiles, projectDir, 'docs/workflow/README.md', workflowReadme(projectName, mode, pack.id), overwritePaths);
28
+ }
29
+ writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/explore.md', governanceTemplateContent('explore.md'), overwritePaths);
30
+ writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/mini-prd.md', governanceTemplateContent('mini-prd.md'), overwritePaths);
31
+ writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/skill-plan.md', governanceTemplateContent('skill-plan.md'), overwritePaths);
32
+ writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/skill-evidence.md', governanceTemplateContent('skill-evidence.md'), overwritePaths);
33
+ writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/runtime.md', governanceTemplateContent('runtime.md'), overwritePaths);
34
+ writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/reality-check.md', governanceTemplateContent('reality-check.md'), overwritePaths);
35
+ writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/resource-cleanup.md', governanceTemplateContent('resource-cleanup.md'), overwritePaths);
36
+ writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/ui-spec.md', governanceTemplateContent('ui-spec.md'), overwritePaths);
37
+ writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/visual-review.md', governanceTemplateContent('visual-review.md'), overwritePaths);
38
+ writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/api-contract.md', governanceTemplateContent('api-contract.md'), overwritePaths);
39
+ writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/docs-impact.md', governanceTemplateContent('docs-impact.md'), overwritePaths);
40
+ writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/resource-impact.md', governanceTemplateContent('resource-impact.md'), overwritePaths);
41
+ writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/standards-impact.md', governanceTemplateContent('standards-impact.md'), overwritePaths);
42
+ writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/architecture-review.md', governanceTemplateContent('architecture-review.md'), overwritePaths);
43
+ writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/security-review.md', governanceTemplateContent('security-review.md'), overwritePaths);
44
+ writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/db-change-plan.md', governanceTemplateContent('db-change-plan.md'), overwritePaths);
45
+ writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/e2e-plan.md', governanceTemplateContent('e2e-plan.md'), overwritePaths);
46
+ writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/product-smoke.md', governanceTemplateContent('product-smoke.md'), overwritePaths);
47
+ writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/plan.md', governanceTemplateContent('plan.md'), overwritePaths);
48
+ writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/verification.md', governanceTemplateContent('verification.md'), overwritePaths);
49
+ writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/review.md', governanceTemplateContent('review.md'), overwritePaths);
50
+ writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/summary.md', governanceTemplateContent('summary.md'), overwritePaths);
51
+ writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/github-actions-scale-preflight.yml', githubActionsPreflightTemplate(), overwritePaths);
52
+ writeTracked(result, lockFiles, projectDir, 'docs/workflow/templates/pre-push-scale-preflight.sh', prePushPreflightTemplate(), overwritePaths);
53
+ writeTracked(result, lockFiles, projectDir, 'docs/worklog/metrics.md', metricsTemplate(), overwritePaths);
54
+ writeTracked(result, lockFiles, projectDir, 'scripts/qa/product-smoke.ps1', productSmokePowerShellScript(), overwritePaths);
55
+ writeTracked(result, lockFiles, projectDir, 'scripts/qa/product-smoke.sh', productSmokeShellScript(), overwritePaths);
50
56
  writeTracked(result, lockFiles, projectDir, '.scale/verification.json', verificationMatrixTemplate(mode, {
51
57
  services,
52
58
  exclude,
53
59
  artifactGate: packMode.artifactGate,
54
- }));
55
- writeTracked(result, lockFiles, projectDir, '.scale/skills.json', skillRoutingPolicyTemplate(mode));
56
- writeTracked(result, lockFiles, projectDir, '.scale/tools.json', toolPolicyTemplate(toolModeFromGovernanceMode(mode)));
57
- writeTracked(result, lockFiles, projectDir, '.scale/resource-policy.json', resourcePolicyTemplate());
58
- writeTracked(result, lockFiles, projectDir, '.scale/assets.json', resourceManifestTemplate());
59
- writeTracked(result, lockFiles, projectDir, '.scale/output-policy.json', outputPolicyTemplate());
60
- writeTracked(result, lockFiles, projectDir, '.scale/product-smoke.json', productSmokeConfigTemplate(mode));
61
- writeTracked(result, lockFiles, projectDir, '.scale/engineering-standards.json', engineeringStandardsPolicyTemplate());
62
- writeTracked(result, lockFiles, projectDir, '.scale/engineering-standards-baseline.json', engineeringStandardsBaselineTemplate());
63
- writeTracked(result, lockFiles, projectDir, '.scale/frameworks.json', frameworksCatalogTemplate());
60
+ }), overwritePaths);
61
+ writeTracked(result, lockFiles, projectDir, '.scale/skills.json', skillRoutingPolicyTemplate(mode), overwritePaths);
62
+ writeTracked(result, lockFiles, projectDir, '.scale/tools.json', toolPolicyTemplate(toolModeFromGovernanceMode(mode)), overwritePaths);
63
+ writeTracked(result, lockFiles, projectDir, '.scale/resource-policy.json', resourcePolicyTemplate(), overwritePaths);
64
+ writeTracked(result, lockFiles, projectDir, '.scale/assets.json', resourceManifestTemplate(), overwritePaths);
65
+ writeTracked(result, lockFiles, projectDir, '.scale/output-policy.json', outputPolicyTemplate(), overwritePaths);
66
+ writeTracked(result, lockFiles, projectDir, '.scale/product-smoke.json', productSmokeConfigTemplate(mode), overwritePaths);
67
+ writeTracked(result, lockFiles, projectDir, '.scale/engineering-standards.json', engineeringStandardsPolicyTemplate(), overwritePaths);
68
+ writeTracked(result, lockFiles, projectDir, '.scale/engineering-standards-baseline.json', engineeringStandardsBaselineTemplate(), overwritePaths);
69
+ writeTracked(result, lockFiles, projectDir, '.scale/frameworks.json', frameworksCatalogTemplate(), overwritePaths);
64
70
  for (const file of pack.generatedFiles) {
65
- writePackGeneratedFile(result, lockFiles, projectDir, pack.id, pack.version, file);
71
+ writePackGeneratedFile(result, lockFiles, projectDir, pack.id, pack.version, file, overwritePaths);
66
72
  }
67
73
  const lockPath = join(projectDir, '.scale', 'governance.lock.json');
68
74
  writeGovernanceLock(projectDir, {
@@ -100,29 +106,34 @@ export function governanceTemplateContent(name) {
100
106
  case 'summary.md': return summaryTemplate();
101
107
  }
102
108
  }
103
- function writeIfMissing(result, path, content) {
109
+ function writeIfMissing(result, path, content, overwrite = false) {
104
110
  if (existsSync(path)) {
111
+ if (overwrite) {
112
+ writeFileSync(path, content, 'utf-8');
113
+ result.updated.push(path);
114
+ return 'updated';
115
+ }
105
116
  result.skipped.push(path);
106
- return false;
117
+ return 'skipped';
107
118
  }
108
119
  const dir = path.split(/[\\/]/).slice(0, -1).join('/');
109
120
  if (dir && !existsSync(dir))
110
121
  mkdirSync(dir, { recursive: true });
111
122
  writeFileSync(path, content, 'utf-8');
112
123
  result.created.push(path);
113
- return true;
124
+ return 'created';
114
125
  }
115
- function writeTracked(result, lockFiles, projectDir, relativePath, content) {
116
- const created = writeIfMissing(result, join(projectDir, relativePath), content);
117
- if (created)
126
+ function writeTracked(result, lockFiles, projectDir, relativePath, content, overwritePaths) {
127
+ const status = writeIfMissing(result, join(projectDir, relativePath), content, overwritePaths.has(relativePath));
128
+ if (status !== 'skipped')
118
129
  lockFiles.set(relativePath, { path: relativePath, owned: true });
119
130
  }
120
- function writePackGeneratedFile(result, lockFiles, projectDir, packId, packVersion, file) {
131
+ function writePackGeneratedFile(result, lockFiles, projectDir, packId, packVersion, file, overwritePaths) {
121
132
  const content = shouldUseGeneratedHeader(file)
122
133
  ? generatedHeader(packId, packVersion) + file.content
123
134
  : file.content;
124
- const created = writeIfMissing(result, join(projectDir, file.path), content);
125
- if (created)
135
+ const status = writeIfMissing(result, join(projectDir, file.path), content, overwritePaths.has(file.path));
136
+ if (status !== 'skipped')
126
137
  lockFiles.set(file.path, { path: file.path, owned: file.owned });
127
138
  }
128
139
  function detectRootServices(projectDir, packId) {
@@ -162,521 +173,521 @@ function shouldUseGeneratedHeader(file) {
162
173
  return file.kind === 'doc' || file.kind === 'template' || file.kind === 'script';
163
174
  }
164
175
  function generatedHeader(packId, packVersion) {
165
- return `# Generated by scale-engine governance pack: ${packId}@${packVersion}
166
- # Edit policy: prefer editing the pack in scale-engine; local overrides should be documented.
167
-
176
+ return `# Generated by scale-engine governance pack: ${packId}@${packVersion}
177
+ # Edit policy: prefer editing the pack in scale-engine; local overrides should be documented.
178
+
168
179
  `;
169
180
  }
170
181
  function workflowReadme(projectName, mode, packId = 'standard') {
171
- return `# ${projectName} Workflow
172
-
173
- Governance mode: ${mode}
174
- Governance pack: ${packId}
175
-
176
- ## Task Levels
177
-
178
- | Level | Use for | Required artifacts |
179
- | --- | --- | --- |
180
- | S | typo, comments, small local edits | relevant validation only |
181
- | M | bug fixes, new APIs, 2-5 files | explore, skill plan, plan, verification, review, summary |
182
- | L | cross-module or architecture changes | full artifacts plus human confirmation |
183
- | CRITICAL | auth, permissions, migrations, production config | rollback plan, security review, full verification |
184
-
185
- ## Standard Task Directory
186
-
187
- \`\`\`text
188
- .planning/tasks/<yyyy-mm-dd>-<task-slug>/
189
- ├── explore.md
190
- ├── mini-prd.md
191
- ├── plan.md
192
- ├── runtime.md
193
- ├── reality-check.md
194
- ├── resource-cleanup.md
195
- ├── verification.md
196
- ├── review.md
197
- ├── summary.md
198
- ├── artifact-manifest.json
199
- └── artifacts/
200
- ├── index.html
201
- └── release-report.html
202
- \`\`\`
203
-
204
- ## Verification
205
-
206
- Use service-aware verification when configured:
207
-
208
- \`\`\`bash
209
- scale preflight --service all
210
- scale preflight --service all --preflight-profile full
211
- scale verify <task-id> --profile default
212
- scale verify <task-id> --service <service-name>
213
- scale verify <task-id> --artifact-gate warn
214
- scale verify <task-id> --artifact-gate block
215
- scale verify <task-id> --require-installed-skills
216
- scale verify <task-id> --profile productSmoke
217
- scale task-artifacts check --dir .planning/tasks/<task-dir> --level L
218
- scale artifact render --task-id <task-dir> --type release-report
219
- scale artifact doctor --task-id <task-dir>
220
- \`\`\`
221
-
222
- Keep \`.scale/verification.json\` as the source of truth for profiles and service commands.
223
- Keep \`.scale/skills.json\` as the source of truth for active skill routing policy.
224
- Keep \`.scale/output-policy.json\` as the source of truth for derived HTML artifact types, source Markdown mapping, security policy, and Git retention behavior.
225
- Keep \`.scale/resource-policy.json\` and \`.scale/assets.json\` as the source of truth for generated reports, temporary files, module documentation, media, reusable scripts, and Git retention policy.
226
- Keep \`.scale/engineering-standards.json\` and \`.scale/frameworks.json\` as the source of truth for logging, security, ORM, architecture, framework, UI/UX, testing, and coding standard checks.
227
- Keep \`.scale/engineering-standards-baseline.json\` as the temporary exception list for known legacy standards findings; it must not be used to hide new or changed-file problems.
228
- Use \`artifactGate: "warn"\` while introducing the workflow, then move M/L/CRITICAL work to \`"block"\` once templates and local gates are stable.
229
-
230
- ## Workflow Upgrade
231
-
232
- Do not rerun \`scale init\` as a blind upgrade command. Generated governance files may contain local project adaptations.
233
-
234
- Use the guarded upgrade flow:
235
-
236
- \`\`\`bash
237
- scale upgrade check --dir .
238
- scale upgrade plan --dir . --html
239
- scale upgrade apply --dir . --confirm
240
- scale upgrade rollback --dir .
241
- scale tools outdated --dir .
242
- scale skill outdated --dir .
243
- scale preflight --preflight-profile quick
244
- \`\`\`
245
-
246
- Rules:
247
-
248
- - \`.scale/governance.lock.json\` records generated file hashes and pack versions.
249
- - Clean or missing generated files can be planned safely.
250
- - Locally changed generated files require manual review before replacement or merge.
251
- - \`scale upgrade apply --confirm\` only restores missing generated files and refreshes the lock after writing \`.scale/backups/upgrade-*/manifest.json\`.
252
- - \`scale upgrade rollback\` only rolls back the latest SCALE-managed safe apply.
253
- - Third-party skills, MCP servers, browser tools, desktop automation, and external CLI tools are never auto-installed by the upgrade flow.
254
- - Community sources require source, install script, permission, and changelog review. Desktop automation is treated as high risk.
255
-
256
- ## HTML Artifacts
257
-
258
- Markdown remains the editable source of truth for task artifacts. HTML artifacts are derived human-review surfaces for plan comparison, implementation plans, code reviews, status reports, incident reports, and release reports.
259
-
260
- Use HTML when a human needs to compare, review, or sign off. Keep source Markdown, manifest metadata, and safety checks in place so the derived HTML stays traceable and does not leak secrets or remote scripts.
261
-
262
- ## Active Skill Routing
263
-
264
- SCALE plans required skills from task description, service selection, and changed files. UI/API work requires a Mini-PRD plus domain evidence such as \`ui-spec.md\`, \`visual-review.md\`, or \`api-contract.md\`. Security and database work require explicit review or rollback artifacts.
265
-
266
- Tool orchestration is part of the workflow contract:
267
-
268
- - UI/UX work requires \`frontend-design\` and \`ui-ux-pro-max\`, and should consider \`awesome-design-md\`, browser screenshots, responsive checks, and visual review evidence.
269
- - Web research, logged-in pages, and dynamic browser work require \`web-access\` evidence, source citations, and browser/network/console evidence when available.
270
- - Browser E2E work should combine \`webapp-testing\`, Playwright, Agent Browser, web-access, or Chrome DevTools MCP according to the target and record screenshots plus console/network findings.
271
- - Desktop or client-side GUI automation uses CUA/computer-use only with explicit operator-safety notes, desktop screenshots, and a side-effect boundary.
272
- - External agent or CLI orchestration such as Codex, Gemini CLI, OpenCode, WPS, or WeChat automation must record version checks, exact commands, output summaries, and dry-run or safe-mode evidence.
273
-
274
- When a task records \`servicesTouched\`, \`scale verify <task-id>\` uses those services automatically. You can still override selection with \`--service all\`, \`--service api\`, or \`--service api,gateway\`.
275
-
276
- Before M/L work, check whether required workflow skills are physically installed:
277
-
278
- \`\`\`bash
279
- scale skill doctor --json
280
- scale skill check --require-installed --json
281
- \`\`\`
282
-
283
- ## Workspace Lifecycle
284
-
285
- Before finishing an agent-created branch or deleting a temporary worktree, inspect root and child repository state:
286
-
287
- \`\`\`bash
288
- scale workspace status --json
289
- scale workspace finish --summary
290
- scale workspace finish --json
291
- scale workspace cleanup --dir <temporary-worktree> --dry-run --json
292
- scale workspace cleanup --dir <temporary-worktree> --apply --confirm <branch-or-head> --json
293
- \`\`\`
294
-
295
- Do not remove a temporary worktree while any submodule or nested repository has uncommitted or unpushed work. Child repositories must be committed and reviewed in their own remotes, then the root repository can record any required pointer or governance updates. Cleanup defaults to dry-run. Applying cleanup requires the reported confirmation token, normally the temporary branch name.
296
-
297
- Use \`scale ship <task-id>\` for governed commits. It checks MOE/submodule child repository state before staging reviewed root files, so dirty or unpushed child work cannot be hidden inside a root commit. It also enforces the GitLab Flow branch lifecycle: work happens on short branches, merges target \`dev\`, production lands on \`master\`, and release publishing is triggered by user-created \`vX.Y.Z\` tags. Direct governed commits on \`dev\`, \`master\`, \`main\`, or detached HEAD are blocked. Raw \`git add .\` is outside the governed path and must not be used for MOE releases.
298
-
299
- ## Resource Governance
300
-
301
- Use asset scanning before committing generated reports, media, temporary scripts, or long-lived documentation changes:
302
-
303
- \`\`\`bash
304
- scale assets scan --json
305
- scale assets doctor --json
306
- scale assets settle --task-id <task-id> --artifact-dir .planning/tasks/<task-dir>
307
- \`\`\`
308
-
309
- Default policy:
310
-
311
- - maintained module docs, standards, contracts, ADRs, reusable scripts: commit and keep current.
312
- - task planning, verification, runtime-contract, reality-check, and cleanup artifacts: keep in \`.planning/tasks\`; promote final truth to maintained docs when useful.
313
- - screenshots, videos, E2E reports, coverage, temporary scripts, and runtime logs: keep out of Git unless explicitly promoted.
314
- - large media: use Git LFS or external artifact storage instead of normal Git history.
315
-
316
- ## Engineering Standards
317
-
318
- Use standards scanning before reviewing or shipping M/L/CRITICAL work:
319
-
320
- \`\`\`bash
321
- scale standards scan --json
322
- scale standards doctor --json
323
- scale standards doctor --changed --json
324
- scale standards doctor --changed-files src/example.ts,src/example.test.ts --json
325
- scale standards baseline --write --artifact-dir .planning/tasks/<task-dir> --task-id <task-id> --json
326
- scale standards settle --task-id <task-id> --artifact-dir .planning/tasks/<task-dir>
327
- scale preflight --preflight-profile full --json
328
- scale verify <task-id> --json
329
- \`\`\`
330
-
331
- Default policy:
332
-
333
- - ad-hoc console/output logging is allowed only for CLI/script paths.
334
- - sensitive fields such as token, password, secret, authorization, cookie, and credentials must not be logged.
335
- - hardcoded secret-like assignments are blocked before review or release.
336
- - SQL must use parameterized queries, ORM bind parameters, or safe query builders.
337
- - unsafe HTML sinks, dynamic code execution, empty catch blocks, and type suppressions require remediation before release.
338
- - framework and architecture rules live in \`.scale/frameworks.json\` and module standards docs.
339
- - \`.scale/frameworks.json > bannedImports\` blocks direct use of deprecated ORMs, unsafe SDKs, or off-system UI components.
340
- - \`.scale/frameworks.json > lastReviewedAt/reviewIntervalDays\` warns when module framework decisions need review.
341
- - \`.scale/engineering-standards.json > blockingRules\` promotes selected warning rule IDs to release-blocking findings.
342
- - \`.scale/engineering-standards.json > allowedFindingPatterns\` allows narrow rule/path/evidence exceptions without hiding unrelated findings in the same file.
343
- - \`.scale/engineering-standards-baseline.json\` may hold known legacy findings during rollout, but normal task gates should prefer \`--changed\` or \`--changed-files\` so new work is blocked without forcing a whole-repo cleanup.
344
- - \`.scale/verification.json > policy.engineeringStandardsGate\` controls whether preflight and task verification treat standards as \`off\`, \`warn\`, or \`block\`.
345
- - \`.scale/product-smoke.json\` defines real product-path probes. Use it to prove a routed user/business flow, not only build, unit tests, or \`/health\`.
346
- - \`.scale/verification.json > policy.productSmokeGate\` controls whether missing or failed product smoke evidence warns or blocks M/L/CRITICAL delivery.
347
- - Full standards scans are for release readiness, scheduled remediation, and architecture cleanup. Changed-file scans are the default for day-to-day feature and bug branches.
348
- - Use \`scale standards baseline --write\` only during an explicit rollout or remediation planning task. It writes the machine-readable baseline and a \`standards-legacy-debt.md\` classification report for staged cleanup.
349
-
350
- ## Automation Templates
351
-
352
- Optional automation templates are generated under \`docs/workflow/templates/\`:
353
-
354
- - \`github-actions-scale-preflight.yml\`: CI workflow that runs \`scale preflight --service all --preflight-profile ci\`.
355
- - \`pre-push-scale-preflight.sh\`: local pre-push hook template that runs the default quick preflight.
356
-
357
- Keep these templates advisory until \`scale preflight --service all --preflight-profile full\` is reliable locally for the project.
182
+ return `# ${projectName} Workflow
183
+
184
+ Governance mode: ${mode}
185
+ Governance pack: ${packId}
186
+
187
+ ## Task Levels
188
+
189
+ | Level | Use for | Required artifacts |
190
+ | --- | --- | --- |
191
+ | S | typo, comments, small local edits | relevant validation only |
192
+ | M | bug fixes, new APIs, 2-5 files | explore, skill plan, plan, verification, review, summary |
193
+ | L | cross-module or architecture changes | full artifacts plus human confirmation |
194
+ | CRITICAL | auth, permissions, migrations, production config | rollback plan, security review, full verification |
195
+
196
+ ## Standard Task Directory
197
+
198
+ \`\`\`text
199
+ .planning/tasks/<yyyy-mm-dd>-<task-slug>/
200
+ ├── explore.md
201
+ ├── mini-prd.md
202
+ ├── plan.md
203
+ ├── runtime.md
204
+ ├── reality-check.md
205
+ ├── resource-cleanup.md
206
+ ├── verification.md
207
+ ├── review.md
208
+ ├── summary.md
209
+ ├── artifact-manifest.json
210
+ └── artifacts/
211
+ ├── index.html
212
+ └── release-report.html
213
+ \`\`\`
214
+
215
+ ## Verification
216
+
217
+ Use service-aware verification when configured:
218
+
219
+ \`\`\`bash
220
+ scale preflight --service all
221
+ scale preflight --service all --preflight-profile full
222
+ scale verify <task-id> --profile default
223
+ scale verify <task-id> --service <service-name>
224
+ scale verify <task-id> --artifact-gate warn
225
+ scale verify <task-id> --artifact-gate block
226
+ scale verify <task-id> --require-installed-skills
227
+ scale verify <task-id> --profile productSmoke
228
+ scale task-artifacts check --dir .planning/tasks/<task-dir> --level L
229
+ scale artifact render --task-id <task-dir> --type release-report
230
+ scale artifact doctor --task-id <task-dir>
231
+ \`\`\`
232
+
233
+ Keep \`.scale/verification.json\` as the source of truth for profiles and service commands.
234
+ Keep \`.scale/skills.json\` as the source of truth for active skill routing policy.
235
+ Keep \`.scale/output-policy.json\` as the source of truth for derived HTML artifact types, source Markdown mapping, security policy, and Git retention behavior.
236
+ Keep \`.scale/resource-policy.json\` and \`.scale/assets.json\` as the source of truth for generated reports, temporary files, module documentation, media, reusable scripts, and Git retention policy.
237
+ Keep \`.scale/engineering-standards.json\` and \`.scale/frameworks.json\` as the source of truth for logging, security, ORM, architecture, framework, UI/UX, testing, and coding standard checks.
238
+ Keep \`.scale/engineering-standards-baseline.json\` as the temporary exception list for known legacy standards findings; it must not be used to hide new or changed-file problems.
239
+ Use \`artifactGate: "warn"\` while introducing the workflow, then move M/L/CRITICAL work to \`"block"\` once templates and local gates are stable.
240
+
241
+ ## Workflow Upgrade
242
+
243
+ Do not rerun \`scale init\` as a blind upgrade command. Generated governance files may contain local project adaptations.
244
+
245
+ Use the guarded upgrade flow:
246
+
247
+ \`\`\`bash
248
+ scale upgrade check --dir .
249
+ scale upgrade plan --dir . --html
250
+ scale upgrade apply --dir . --confirm
251
+ scale upgrade rollback --dir .
252
+ scale tools outdated --dir .
253
+ scale skill outdated --dir .
254
+ scale preflight --preflight-profile quick
255
+ \`\`\`
256
+
257
+ Rules:
258
+
259
+ - \`.scale/governance.lock.json\` records generated file hashes and pack versions.
260
+ - Clean or missing generated files can be planned safely.
261
+ - Locally changed generated files require manual review before replacement or merge.
262
+ - \`scale upgrade apply --confirm\` only restores missing generated files and refreshes the lock after writing \`.scale/backups/upgrade-*/manifest.json\`.
263
+ - \`scale upgrade rollback\` only rolls back the latest SCALE-managed safe apply.
264
+ - Third-party skills, MCP servers, browser tools, desktop automation, and external CLI tools are never auto-installed by the upgrade flow.
265
+ - Community sources require source, install script, permission, and changelog review. Desktop automation is treated as high risk.
266
+
267
+ ## HTML Artifacts
268
+
269
+ Markdown remains the editable source of truth for task artifacts. HTML artifacts are derived human-review surfaces for plan comparison, implementation plans, code reviews, status reports, incident reports, and release reports.
270
+
271
+ Use HTML when a human needs to compare, review, or sign off. Keep source Markdown, manifest metadata, and safety checks in place so the derived HTML stays traceable and does not leak secrets or remote scripts.
272
+
273
+ ## Active Skill Routing
274
+
275
+ SCALE plans required skills from task description, service selection, and changed files. UI/API work requires a Mini-PRD plus domain evidence such as \`ui-spec.md\`, \`visual-review.md\`, or \`api-contract.md\`. Security and database work require explicit review or rollback artifacts.
276
+
277
+ Tool orchestration is part of the workflow contract:
278
+
279
+ - UI/UX work requires \`frontend-design\` and \`ui-ux-pro-max\`, and should consider \`awesome-design-md\`, browser screenshots, responsive checks, and visual review evidence.
280
+ - Web research, logged-in pages, and dynamic browser work require \`web-access\` evidence, source citations, and browser/network/console evidence when available.
281
+ - Browser E2E work should combine \`webapp-testing\`, Playwright, Agent Browser, web-access, or Chrome DevTools MCP according to the target and record screenshots plus console/network findings.
282
+ - Desktop or client-side GUI automation uses CUA/computer-use only with explicit operator-safety notes, desktop screenshots, and a side-effect boundary.
283
+ - External agent or CLI orchestration such as Codex, Gemini CLI, OpenCode, WPS, or WeChat automation must record version checks, exact commands, output summaries, and dry-run or safe-mode evidence.
284
+
285
+ When a task records \`servicesTouched\`, \`scale verify <task-id>\` uses those services automatically. You can still override selection with \`--service all\`, \`--service api\`, or \`--service api,gateway\`.
286
+
287
+ Before M/L work, check whether required workflow skills are physically installed:
288
+
289
+ \`\`\`bash
290
+ scale skill doctor --json
291
+ scale skill check --require-installed --json
292
+ \`\`\`
293
+
294
+ ## Workspace Lifecycle
295
+
296
+ Before finishing an agent-created branch or deleting a temporary worktree, inspect root and child repository state:
297
+
298
+ \`\`\`bash
299
+ scale workspace status --json
300
+ scale workspace finish --summary
301
+ scale workspace finish --json
302
+ scale workspace cleanup --dir <temporary-worktree> --dry-run --json
303
+ scale workspace cleanup --dir <temporary-worktree> --apply --confirm <branch-or-head> --json
304
+ \`\`\`
305
+
306
+ Do not remove a temporary worktree while any submodule or nested repository has uncommitted or unpushed work. Child repositories must be committed and reviewed in their own remotes, then the root repository can record any required pointer or governance updates. Cleanup defaults to dry-run. Applying cleanup requires the reported confirmation token, normally the temporary branch name.
307
+
308
+ Use \`scale ship <task-id>\` for governed commits. It checks MOE/submodule child repository state before staging reviewed root files, so dirty or unpushed child work cannot be hidden inside a root commit. It also enforces the GitLab Flow branch lifecycle: work happens on short branches, merges target \`dev\`, production lands on \`master\`, and release publishing is triggered by user-created \`vX.Y.Z\` tags. Direct governed commits on \`dev\`, \`master\`, \`main\`, or detached HEAD are blocked. Raw \`git add .\` is outside the governed path and must not be used for MOE releases.
309
+
310
+ ## Resource Governance
311
+
312
+ Use asset scanning before committing generated reports, media, temporary scripts, or long-lived documentation changes:
313
+
314
+ \`\`\`bash
315
+ scale assets scan --json
316
+ scale assets doctor --json
317
+ scale assets settle --task-id <task-id> --artifact-dir .planning/tasks/<task-dir>
318
+ \`\`\`
319
+
320
+ Default policy:
321
+
322
+ - maintained module docs, standards, contracts, ADRs, reusable scripts: commit and keep current.
323
+ - task planning, verification, runtime-contract, reality-check, and cleanup artifacts: keep in \`.planning/tasks\`; promote final truth to maintained docs when useful.
324
+ - screenshots, videos, E2E reports, coverage, temporary scripts, and runtime logs: keep out of Git unless explicitly promoted.
325
+ - large media: use Git LFS or external artifact storage instead of normal Git history.
326
+
327
+ ## Engineering Standards
328
+
329
+ Use standards scanning before reviewing or shipping M/L/CRITICAL work:
330
+
331
+ \`\`\`bash
332
+ scale standards scan --json
333
+ scale standards doctor --json
334
+ scale standards doctor --changed --json
335
+ scale standards doctor --changed-files src/example.ts,src/example.test.ts --json
336
+ scale standards baseline --write --artifact-dir .planning/tasks/<task-dir> --task-id <task-id> --json
337
+ scale standards settle --task-id <task-id> --artifact-dir .planning/tasks/<task-dir>
338
+ scale preflight --preflight-profile full --json
339
+ scale verify <task-id> --json
340
+ \`\`\`
341
+
342
+ Default policy:
343
+
344
+ - ad-hoc console/output logging is allowed only for CLI/script paths.
345
+ - sensitive fields such as token, password, secret, authorization, cookie, and credentials must not be logged.
346
+ - hardcoded secret-like assignments are blocked before review or release.
347
+ - SQL must use parameterized queries, ORM bind parameters, or safe query builders.
348
+ - unsafe HTML sinks, dynamic code execution, empty catch blocks, and type suppressions require remediation before release.
349
+ - framework and architecture rules live in \`.scale/frameworks.json\` and module standards docs.
350
+ - \`.scale/frameworks.json > bannedImports\` blocks direct use of deprecated ORMs, unsafe SDKs, or off-system UI components.
351
+ - \`.scale/frameworks.json > lastReviewedAt/reviewIntervalDays\` warns when module framework decisions need review.
352
+ - \`.scale/engineering-standards.json > blockingRules\` promotes selected warning rule IDs to release-blocking findings.
353
+ - \`.scale/engineering-standards.json > allowedFindingPatterns\` allows narrow rule/path/evidence exceptions without hiding unrelated findings in the same file.
354
+ - \`.scale/engineering-standards-baseline.json\` may hold known legacy findings during rollout, but normal task gates should prefer \`--changed\` or \`--changed-files\` so new work is blocked without forcing a whole-repo cleanup.
355
+ - \`.scale/verification.json > policy.engineeringStandardsGate\` controls whether preflight and task verification treat standards as \`off\`, \`warn\`, or \`block\`.
356
+ - \`.scale/product-smoke.json\` defines real product-path probes. Use it to prove a routed user/business flow, not only build, unit tests, or \`/health\`.
357
+ - \`.scale/verification.json > policy.productSmokeGate\` controls whether missing or failed product smoke evidence warns or blocks M/L/CRITICAL delivery.
358
+ - Full standards scans are for release readiness, scheduled remediation, and architecture cleanup. Changed-file scans are the default for day-to-day feature and bug branches.
359
+ - Use \`scale standards baseline --write\` only during an explicit rollout or remediation planning task. It writes the machine-readable baseline and a \`standards-legacy-debt.md\` classification report for staged cleanup.
360
+
361
+ ## Automation Templates
362
+
363
+ Optional automation templates are generated under \`docs/workflow/templates/\`:
364
+
365
+ - \`github-actions-scale-preflight.yml\`: CI workflow that runs \`scale preflight --service all --preflight-profile ci\`.
366
+ - \`pre-push-scale-preflight.sh\`: local pre-push hook template that runs the default quick preflight.
367
+
368
+ Keep these templates advisory until \`scale preflight --service all --preflight-profile full\` is reliable locally for the project.
358
369
  `;
359
370
  }
360
371
  function exploreTemplate() {
361
- return `# Explore
362
-
363
- ## Files Read
364
-
365
- - TBD
366
-
367
- ## Current Behavior
368
-
369
- TBD
370
-
371
- ## Main Conflict
372
-
373
- TBD
374
-
375
- ## Affected Modules
376
-
377
- TBD
378
-
379
- ## Evidence
380
- TBD
372
+ return `# Explore
373
+
374
+ ## Files Read
375
+
376
+ - TBD
377
+
378
+ ## Current Behavior
379
+
380
+ TBD
381
+
382
+ ## Main Conflict
383
+
384
+ TBD
385
+
386
+ ## Affected Modules
387
+
388
+ TBD
389
+
390
+ ## Evidence
391
+ TBD
381
392
  `;
382
393
  }
383
394
  function miniPrdTemplate() {
384
- return `# Mini-PRD
385
-
386
- ## Background
387
-
388
- TBD
389
-
390
- ## Target Users
391
-
392
- TBD
393
-
394
- ## Core Scenario
395
-
396
- TBD
397
-
398
- ## Non-Goals
399
-
400
- TBD
401
-
402
- ## User Path
403
-
404
- TBD
405
-
406
- ## Permission Rules
407
-
408
- TBD
409
-
410
- ## Data Impact
411
-
412
- TBD
413
-
414
- ## Exception Scenarios
415
-
416
- 1. TBD
417
- 2. TBD
418
- 3. TBD
419
-
420
- ## Acceptance Criteria
421
-
422
- - [ ] TBD
423
-
424
- ## Rollback Or Disable Strategy
425
- TBD
395
+ return `# Mini-PRD
396
+
397
+ ## Background
398
+
399
+ TBD
400
+
401
+ ## Target Users
402
+
403
+ TBD
404
+
405
+ ## Core Scenario
406
+
407
+ TBD
408
+
409
+ ## Non-Goals
410
+
411
+ TBD
412
+
413
+ ## User Path
414
+
415
+ TBD
416
+
417
+ ## Permission Rules
418
+
419
+ TBD
420
+
421
+ ## Data Impact
422
+
423
+ TBD
424
+
425
+ ## Exception Scenarios
426
+
427
+ 1. TBD
428
+ 2. TBD
429
+ 3. TBD
430
+
431
+ ## Acceptance Criteria
432
+
433
+ - [ ] TBD
434
+
435
+ ## Rollback Or Disable Strategy
436
+ TBD
426
437
  `;
427
438
  }
428
439
  function skillPlanTemplate() {
429
- return `# Skill Plan
430
-
431
- ## Detected Intents
432
-
433
- | Domain | Score | Evidence |
434
- | --- | ---: | --- |
435
- | | | |
436
-
437
- ## Required Skills
438
-
439
- - TBD
440
-
441
- ## Recommended Skills
442
-
443
- - TBD
444
-
445
- ## Required Artifacts
446
-
447
- - TBD
448
-
449
- ## Required Verification Evidence
450
-
451
- - TBD
452
-
453
- ## Tool Orchestration
454
-
455
- | Capability | Primary Tool Or Skill | Fallback | Required Evidence |
456
- | --- | --- | --- | --- |
457
- | UI/UX design | frontend-design, ui-ux-pro-max | awesome-design-md | design-system, ui-spec.md, visual-review.md |
458
- | Web research or logged-in pages | web-access | agent-browser, Chrome DevTools MCP | source citations, browser evidence |
459
- | Browser E2E | webapp-testing, Playwright | agent-browser, web-access | screenshot, console, network evidence |
460
- | Desktop GUI automation | CUA/computer-use | manual verification | desktop screenshot, operator-safety notes |
461
- | External agent CLI | codex/gemini/opencode CLI | manual review | version check, exact command output |
462
-
463
- ## Skipped Skills
464
-
465
- | Skill | Reason | Fallback Evidence |
466
- | --- | --- | --- |
467
- | | | |
440
+ return `# Skill Plan
441
+
442
+ ## Detected Intents
443
+
444
+ | Domain | Score | Evidence |
445
+ | --- | ---: | --- |
446
+ | | | |
447
+
448
+ ## Required Skills
449
+
450
+ - TBD
451
+
452
+ ## Recommended Skills
453
+
454
+ - TBD
455
+
456
+ ## Required Artifacts
457
+
458
+ - TBD
459
+
460
+ ## Required Verification Evidence
461
+
462
+ - TBD
463
+
464
+ ## Tool Orchestration
465
+
466
+ | Capability | Primary Tool Or Skill | Fallback | Required Evidence |
467
+ | --- | --- | --- | --- |
468
+ | UI/UX design | frontend-design, ui-ux-pro-max | awesome-design-md | design-system, ui-spec.md, visual-review.md |
469
+ | Web research or logged-in pages | web-access | agent-browser, Chrome DevTools MCP | source citations, browser evidence |
470
+ | Browser E2E | webapp-testing, Playwright | agent-browser, web-access | screenshot, console, network evidence |
471
+ | Desktop GUI automation | CUA/computer-use | manual verification | desktop screenshot, operator-safety notes |
472
+ | External agent CLI | codex/gemini/opencode CLI | manual review | version check, exact command output |
473
+
474
+ ## Skipped Skills
475
+
476
+ | Skill | Reason | Fallback Evidence |
477
+ | --- | --- | --- |
478
+ | | | |
468
479
  `;
469
480
  }
470
481
  function skillEvidenceTemplate() {
471
- return `# Skill Evidence
472
-
473
- ## Planned Skills
474
-
475
- - TBD
476
-
477
- ## Tool Selection Rationale
478
-
479
- TBD
480
-
481
- ## Used Skills
482
-
483
- | Skill | Phase | Trigger | Evidence | Status |
484
- | --- | --- | --- | --- | --- |
485
- | skill-id | plan/build/verify/review | why it was selected | command, screenshot, report, or artifact path | executed/skipped/fallback |
486
-
487
- ## Browser Or Web Evidence
488
-
489
- | Tool | Target | Evidence | Result |
490
- | --- | --- | --- | --- |
491
- | web-access/agent-browser/Chrome DevTools MCP | URL or local target | screenshot, console log, network finding, source URL | passed/failed/skipped |
492
-
493
- ## Desktop Or External CLI Evidence
494
-
495
- | Tool | Scope | Safety Boundary | Evidence | Result |
496
- | --- | --- | --- | --- | --- |
497
- | cua/codex/gemini/opencode/wps/wechat | command or app target | read-only/dry-run/test account/manual approval | output summary, screenshot, or report path | passed/failed/skipped |
498
-
499
- ## Skipped Skills
500
-
501
- | Skill | Reason | Fallback Evidence |
502
- | --- | --- | --- |
503
- | skill-id | why it could not run | manual review, alternate command, or explicit risk |
482
+ return `# Skill Evidence
483
+
484
+ ## Planned Skills
485
+
486
+ - TBD
487
+
488
+ ## Tool Selection Rationale
489
+
490
+ TBD
491
+
492
+ ## Used Skills
493
+
494
+ | Skill | Phase | Trigger | Evidence | Status |
495
+ | --- | --- | --- | --- | --- |
496
+ | skill-id | plan/build/verify/review | why it was selected | command, screenshot, report, or artifact path | executed/skipped/fallback |
497
+
498
+ ## Browser Or Web Evidence
499
+
500
+ | Tool | Target | Evidence | Result |
501
+ | --- | --- | --- | --- |
502
+ | web-access/agent-browser/Chrome DevTools MCP | URL or local target | screenshot, console log, network finding, source URL | passed/failed/skipped |
503
+
504
+ ## Desktop Or External CLI Evidence
505
+
506
+ | Tool | Scope | Safety Boundary | Evidence | Result |
507
+ | --- | --- | --- | --- | --- |
508
+ | cua/codex/gemini/opencode/wps/wechat | command or app target | read-only/dry-run/test account/manual approval | output summary, screenshot, or report path | passed/failed/skipped |
509
+
510
+ ## Skipped Skills
511
+
512
+ | Skill | Reason | Fallback Evidence |
513
+ | --- | --- | --- |
514
+ | skill-id | why it could not run | manual review, alternate command, or explicit risk |
504
515
  `;
505
516
  }
506
517
  function runtimeTemplate() {
507
- return `# Runtime Contract
508
-
509
- ## Configuration Source
510
-
511
- - Source: TBD
512
- - Environment/profile: TBD
513
- - Runtime overrides: TBD
514
- - Secrets boundary: TBD
515
-
516
- ## Service Topology
517
-
518
- | Service | URL Or Command | Config Source | Auth Mode | Status |
519
- | --- | --- | --- | --- | --- |
520
- | TBD | TBD | TBD | TBD | Not checked |
521
-
522
- ## Verification Boundary
523
-
524
- - Confirmed:
525
- - Not covered:
526
- - Credential-gated:
527
- - Environment-gated:
518
+ return `# Runtime Contract
519
+
520
+ ## Configuration Source
521
+
522
+ - Source: TBD
523
+ - Environment/profile: TBD
524
+ - Runtime overrides: TBD
525
+ - Secrets boundary: TBD
526
+
527
+ ## Service Topology
528
+
529
+ | Service | URL Or Command | Config Source | Auth Mode | Status |
530
+ | --- | --- | --- | --- | --- |
531
+ | TBD | TBD | TBD | TBD | Not checked |
532
+
533
+ ## Verification Boundary
534
+
535
+ - Confirmed:
536
+ - Not covered:
537
+ - Credential-gated:
538
+ - Environment-gated:
528
539
  `;
529
540
  }
530
541
  function realityCheckTemplate() {
531
- return `# Reality Check
532
-
533
- ## Confirmed
534
-
535
- - TBD
536
-
537
- ## Not Verified
538
-
539
- - TBD
540
-
541
- ## Stub / Fake / Partial
542
-
543
- - TBD
544
-
545
- ## Credential-Gated
546
-
547
- - TBD
548
-
549
- ## Environment-Gated
550
-
551
- - TBD
552
-
553
- ## User-Visible Risk
554
-
555
- - TBD
542
+ return `# Reality Check
543
+
544
+ ## Confirmed
545
+
546
+ - TBD
547
+
548
+ ## Not Verified
549
+
550
+ - TBD
551
+
552
+ ## Stub / Fake / Partial
553
+
554
+ - TBD
555
+
556
+ ## Credential-Gated
557
+
558
+ - TBD
559
+
560
+ ## Environment-Gated
561
+
562
+ - TBD
563
+
564
+ ## User-Visible Risk
565
+
566
+ - TBD
556
567
  `;
557
568
  }
558
569
  function resourceCleanupTemplate() {
559
- return `# Resource Cleanup
560
-
561
- ## New Resources
562
-
563
- | Resource | Location | Keep / Move / Delete | Reason |
564
- | --- | --- | --- | --- |
565
- | TBD | TBD | TBD | TBD |
566
-
567
- ## Docs Promotion
568
-
569
- - Promote to docs:
570
- - Keep in planning:
571
- - Keep local/runtime only:
572
- - Delete before handoff:
570
+ return `# Resource Cleanup
571
+
572
+ ## New Resources
573
+
574
+ | Resource | Location | Keep / Move / Delete | Reason |
575
+ | --- | --- | --- | --- |
576
+ | TBD | TBD | TBD | TBD |
577
+
578
+ ## Docs Promotion
579
+
580
+ - Promote to docs:
581
+ - Keep in planning:
582
+ - Keep local/runtime only:
583
+ - Delete before handoff:
573
584
  `;
574
585
  }
575
586
  function uiSpecTemplate() {
576
- return `# UI Spec
577
-
578
- ## User Goal
579
-
580
- TBD
581
-
582
- ## Primary Flow
583
-
584
- TBD
585
-
586
- ## Interaction States
587
-
588
- - Default:
589
- - Loading:
590
- - Empty:
591
- - Error:
592
- - Success:
593
-
594
- ## Responsive Behavior
595
-
596
- TBD
597
-
598
- ## Accessibility Requirements
599
-
600
- TBD
601
-
602
- ## Acceptance Criteria
603
-
604
- - [ ] TBD
587
+ return `# UI Spec
588
+
589
+ ## User Goal
590
+
591
+ TBD
592
+
593
+ ## Primary Flow
594
+
595
+ TBD
596
+
597
+ ## Interaction States
598
+
599
+ - Default:
600
+ - Loading:
601
+ - Empty:
602
+ - Error:
603
+ - Success:
604
+
605
+ ## Responsive Behavior
606
+
607
+ TBD
608
+
609
+ ## Accessibility Requirements
610
+
611
+ TBD
612
+
613
+ ## Acceptance Criteria
614
+
615
+ - [ ] TBD
605
616
  `;
606
617
  }
607
618
  function visualReviewTemplate() {
608
- return `# Visual Review
609
-
610
- ## Screenshots Or Evidence
611
-
612
- TBD
613
-
614
- ## Layout And Responsiveness
615
-
616
- TBD
617
-
618
- ## Text Fit And Overlap
619
-
620
- TBD
621
-
622
- ## Accessibility Notes
623
-
624
- TBD
625
-
626
- ## Final Verdict
627
- TBD
619
+ return `# Visual Review
620
+
621
+ ## Screenshots Or Evidence
622
+
623
+ TBD
624
+
625
+ ## Layout And Responsiveness
626
+
627
+ TBD
628
+
629
+ ## Text Fit And Overlap
630
+
631
+ TBD
632
+
633
+ ## Accessibility Notes
634
+
635
+ TBD
636
+
637
+ ## Final Verdict
638
+ TBD
628
639
  `;
629
640
  }
630
641
  function apiContractTemplate() {
631
- return `# API Contract
632
-
633
- ## Endpoint Or Interface
634
-
635
- TBD
636
-
637
- ## Request
638
-
639
- TBD
640
-
641
- ## Response
642
-
643
- TBD
644
-
645
- ## Errors
646
-
647
- TBD
648
-
649
- ## Permission Rules
650
-
651
- TBD
652
-
653
- ## Compatibility Notes
654
-
655
- TBD
656
-
657
- ## Acceptance Criteria
658
-
659
- - [ ] TBD
642
+ return `# API Contract
643
+
644
+ ## Endpoint Or Interface
645
+
646
+ TBD
647
+
648
+ ## Request
649
+
650
+ TBD
651
+
652
+ ## Response
653
+
654
+ TBD
655
+
656
+ ## Errors
657
+
658
+ TBD
659
+
660
+ ## Permission Rules
661
+
662
+ TBD
663
+
664
+ ## Compatibility Notes
665
+
666
+ TBD
667
+
668
+ ## Acceptance Criteria
669
+
670
+ - [ ] TBD
660
671
  `;
661
672
  }
662
673
  function docsImpactTemplate() {
663
- return `# Docs Impact
664
-
665
- ## Code Changes Requiring Docs
666
-
667
- - TBD
668
-
669
- ## Documentation Updated
670
-
671
- - TBD
672
-
673
- ## No-Docs-Needed Rationale
674
-
675
- TBD
676
-
677
- ## Links Checked
678
-
679
- - TBD
674
+ return `# Docs Impact
675
+
676
+ ## Code Changes Requiring Docs
677
+
678
+ - TBD
679
+
680
+ ## Documentation Updated
681
+
682
+ - TBD
683
+
684
+ ## No-Docs-Needed Rationale
685
+
686
+ TBD
687
+
688
+ ## Links Checked
689
+
690
+ - TBD
680
691
  `;
681
692
  }
682
693
  function toolModeFromGovernanceMode(mode) {
@@ -687,351 +698,351 @@ function toolModeFromGovernanceMode(mode) {
687
698
  return 'evidence-required';
688
699
  }
689
700
  function resourceImpactTemplate() {
690
- return `# Resource Impact
691
-
692
- ## Resources Created
693
-
694
- | Path | Type | Git Policy | Retention |
695
- | --- | --- | --- | --- |
696
- | TBD | canonical-doc/task-artifact/evidence-report/temporary/reusable-script/generated-media/contract/decision-record | commit/ignore/lfs/external/review | TBD |
697
-
698
- ## Resources Updated
699
-
700
- - TBD
701
-
702
- ## Resources Promoted To Maintained Docs
703
-
704
- - TBD
705
-
706
- ## Resources To Delete Or Archive Before Finish
707
-
708
- - TBD
709
-
710
- ## Source Of Truth Updates
711
-
712
- - [ ] .scale/resource-policy.json
713
- - [ ] .scale/assets.json
714
- - [ ] docs/modules/<module>/README.md
701
+ return `# Resource Impact
702
+
703
+ ## Resources Created
704
+
705
+ | Path | Type | Git Policy | Retention |
706
+ | --- | --- | --- | --- |
707
+ | TBD | canonical-doc/task-artifact/evidence-report/temporary/reusable-script/generated-media/contract/decision-record | commit/ignore/lfs/external/review | TBD |
708
+
709
+ ## Resources Updated
710
+
711
+ - TBD
712
+
713
+ ## Resources Promoted To Maintained Docs
714
+
715
+ - TBD
716
+
717
+ ## Resources To Delete Or Archive Before Finish
718
+
719
+ - TBD
720
+
721
+ ## Source Of Truth Updates
722
+
723
+ - [ ] .scale/resource-policy.json
724
+ - [ ] .scale/assets.json
725
+ - [ ] docs/modules/<module>/README.md
715
726
  `;
716
727
  }
717
728
  function standardsImpactTemplate() {
718
- return `# Standards Impact
719
-
720
- ## Standards Checked
721
-
722
- - [ ] Logging and redaction
723
- - [ ] Architecture boundaries
724
- - [ ] ORM/database access
725
- - [ ] Framework/component conventions
726
- - [ ] UI/UX acceptance where user-facing
727
- - [ ] Test and verification rigor
728
- - [ ] Security-sensitive inputs and outputs
729
-
730
- ## Findings
731
-
732
- | Severity | Rule | Path | Decision |
733
- | --- | --- | --- | --- |
734
- | TBD | TBD | TBD | fix/accept/escalate |
735
-
736
- ## Policy Updates
737
-
738
- - [ ] .scale/engineering-standards.json
739
- - [ ] .scale/frameworks.json
740
- - [ ] docs/standards/
741
-
742
- ## Settlement
743
-
744
- - Standards scan:
745
- - Standards doctor:
729
+ return `# Standards Impact
730
+
731
+ ## Standards Checked
732
+
733
+ - [ ] Logging and redaction
734
+ - [ ] Architecture boundaries
735
+ - [ ] ORM/database access
736
+ - [ ] Framework/component conventions
737
+ - [ ] UI/UX acceptance where user-facing
738
+ - [ ] Test and verification rigor
739
+ - [ ] Security-sensitive inputs and outputs
740
+
741
+ ## Findings
742
+
743
+ | Severity | Rule | Path | Decision |
744
+ | --- | --- | --- | --- |
745
+ | TBD | TBD | TBD | fix/accept/escalate |
746
+
747
+ ## Policy Updates
748
+
749
+ - [ ] .scale/engineering-standards.json
750
+ - [ ] .scale/frameworks.json
751
+ - [ ] docs/standards/
752
+
753
+ ## Settlement
754
+
755
+ - Standards scan:
756
+ - Standards doctor:
746
757
  `;
747
758
  }
748
759
  function architectureReviewTemplate() {
749
- return `# Architecture Review
750
-
751
- ## Scope
752
-
753
- - Modules touched:
754
- - Public contracts touched:
755
- - Data flow touched:
756
-
757
- ## Boundary Checks
758
-
759
- - [ ] API/controller layer does not bypass service/usecase layer
760
- - [ ] Domain layer is not coupled to infrastructure details
761
- - [ ] Repository/ORM usage follows project conventions
762
- - [ ] Shared framework components are reused instead of duplicated
763
- - [ ] New abstractions remove real complexity
764
-
765
- ## Risks
766
-
767
- - TBD
768
-
769
- ## Decision
770
-
771
- - Approved/changes required:
760
+ return `# Architecture Review
761
+
762
+ ## Scope
763
+
764
+ - Modules touched:
765
+ - Public contracts touched:
766
+ - Data flow touched:
767
+
768
+ ## Boundary Checks
769
+
770
+ - [ ] API/controller layer does not bypass service/usecase layer
771
+ - [ ] Domain layer is not coupled to infrastructure details
772
+ - [ ] Repository/ORM usage follows project conventions
773
+ - [ ] Shared framework components are reused instead of duplicated
774
+ - [ ] New abstractions remove real complexity
775
+
776
+ ## Risks
777
+
778
+ - TBD
779
+
780
+ ## Decision
781
+
782
+ - Approved/changes required:
772
783
  `;
773
784
  }
774
785
  function securityReviewTemplate() {
775
- return `# Security Review
776
-
777
- ## Assets And Trust Boundaries
778
-
779
- TBD
780
-
781
- ## Authorization Rules
782
-
783
- TBD
784
-
785
- ## Abuse Cases
786
-
787
- 1. TBD
788
- 2. TBD
789
- 3. TBD
790
-
791
- ## Sensitive Data Impact
792
-
793
- TBD
794
-
795
- ## Rollback Or Disable Strategy
796
-
797
- TBD
798
-
799
- ## Final Verdict
800
- TBD
786
+ return `# Security Review
787
+
788
+ ## Assets And Trust Boundaries
789
+
790
+ TBD
791
+
792
+ ## Authorization Rules
793
+
794
+ TBD
795
+
796
+ ## Abuse Cases
797
+
798
+ 1. TBD
799
+ 2. TBD
800
+ 3. TBD
801
+
802
+ ## Sensitive Data Impact
803
+
804
+ TBD
805
+
806
+ ## Rollback Or Disable Strategy
807
+
808
+ TBD
809
+
810
+ ## Final Verdict
811
+ TBD
801
812
  `;
802
813
  }
803
814
  function dbChangePlanTemplate() {
804
- return `# DB Change Plan
805
-
806
- ## Schema Or Data Change
807
-
808
- TBD
809
-
810
- ## Backward Compatibility
811
-
812
- TBD
813
-
814
- ## Migration Steps
815
-
816
- TBD
817
-
818
- ## Rollback Plan
819
-
820
- TBD
821
-
822
- ## Verification
823
- TBD
815
+ return `# DB Change Plan
816
+
817
+ ## Schema Or Data Change
818
+
819
+ TBD
820
+
821
+ ## Backward Compatibility
822
+
823
+ TBD
824
+
825
+ ## Migration Steps
826
+
827
+ TBD
828
+
829
+ ## Rollback Plan
830
+
831
+ TBD
832
+
833
+ ## Verification
834
+ TBD
824
835
  `;
825
836
  }
826
837
  function e2ePlanTemplate() {
827
- return `# E2E Plan
828
-
829
- ## User Paths
830
-
831
- TBD
832
-
833
- ## Browser Coverage
834
-
835
- TBD
836
-
837
- ## Test Data
838
-
839
- TBD
840
-
841
- ## Assertions
842
-
843
- TBD
844
-
845
- ## Evidence
846
- TBD
838
+ return `# E2E Plan
839
+
840
+ ## User Paths
841
+
842
+ TBD
843
+
844
+ ## Browser Coverage
845
+
846
+ TBD
847
+
848
+ ## Test Data
849
+
850
+ TBD
851
+
852
+ ## Assertions
853
+
854
+ TBD
855
+
856
+ ## Evidence
857
+ TBD
847
858
  `;
848
859
  }
849
860
  function productSmokeTemplate() {
850
- return `# Product Smoke
851
-
852
- ## Real Product Path
853
-
854
- Describe the smallest end-to-end path that proves the change works through the real product boundary.
855
-
856
- Example:
857
-
858
- \`\`\`text
859
- UI or client -> gateway/router -> service -> database/storage/queue -> observable result
860
- \`\`\`
861
-
862
- Do not use a green health endpoint as the only proof when the user-facing path depends on routing, authentication, storage, async tasks, browser behavior, or third-party integration.
863
-
864
- ## Quick Setup
865
-
866
- 1. Open \`.scale/product-smoke.json\`.
867
- 2. Replace the example command with one real product path command.
868
- 3. Set that probe's \`enabled\` field to \`true\`.
869
- 4. Run \`scale preflight --profile productSmoke --json\`.
870
- 5. Run \`scale runtime final-check --level M --json\`.
871
-
872
- \`status: "skipped"\` means no real product path was exercised. It does not count as completion evidence.
873
-
874
- ## Setup
875
-
876
- - Base URL:
877
- - Test user or tenant:
878
- - Required fixtures:
879
- - Services that must be running:
880
-
881
- ## Smoke Commands
882
-
883
- | Command | Expected Result | Evidence Artifact |
884
- | --- | --- | --- |
885
- | TBD | TBD | TBD |
886
-
887
- ## Runtime Evidence
888
-
889
- Record at least one runtime evidence item:
890
-
891
- \`\`\`bash
892
- scale runtime record \\
893
- --kind command \\
894
- --title "Product smoke: <flow>" \\
895
- --status passed \\
896
- --command "<exact smoke command>" \\
897
- --exit-code 0 \\
898
- --summary "<business result, task id, status, or observable output>" \\
899
- --artifacts ".agent/logs/<service>/<smoke>.json" \\
900
- --metadata-json '{"productSmoke":true,"realProductPath":true}'
901
- \`\`\`
902
-
903
- ## Assertions
904
-
905
- - [ ] Request crossed the real product boundary, not only an isolated unit.
906
- - [ ] Authentication or user identity path was exercised when relevant.
907
- - [ ] Persistence/storage/queue side effect was verified when relevant.
908
- - [ ] Async task or eventual state was polled to terminal status when relevant.
909
- - [ ] Failure output is specific enough to diagnose the failing layer.
910
- - [ ] Runtime artifacts are ignored or deliberately promoted according to resource governance.
861
+ return `# Product Smoke
862
+
863
+ ## Real Product Path
864
+
865
+ Describe the smallest end-to-end path that proves the change works through the real product boundary.
866
+
867
+ Example:
868
+
869
+ \`\`\`text
870
+ UI or client -> gateway/router -> service -> database/storage/queue -> observable result
871
+ \`\`\`
872
+
873
+ Do not use a green health endpoint as the only proof when the user-facing path depends on routing, authentication, storage, async tasks, browser behavior, or third-party integration.
874
+
875
+ ## Quick Setup
876
+
877
+ 1. Open \`.scale/product-smoke.json\`.
878
+ 2. Replace the example command with one real product path command.
879
+ 3. Set that probe's \`enabled\` field to \`true\`.
880
+ 4. Run \`scale preflight --profile productSmoke --json\`.
881
+ 5. Run \`scale runtime final-check --level M --json\`.
882
+
883
+ \`status: "skipped"\` means no real product path was exercised. It does not count as completion evidence.
884
+
885
+ ## Setup
886
+
887
+ - Base URL:
888
+ - Test user or tenant:
889
+ - Required fixtures:
890
+ - Services that must be running:
891
+
892
+ ## Smoke Commands
893
+
894
+ | Command | Expected Result | Evidence Artifact |
895
+ | --- | --- | --- |
896
+ | TBD | TBD | TBD |
897
+
898
+ ## Runtime Evidence
899
+
900
+ Record at least one runtime evidence item:
901
+
902
+ \`\`\`bash
903
+ scale runtime record \\
904
+ --kind command \\
905
+ --title "Product smoke: <flow>" \\
906
+ --status passed \\
907
+ --command "<exact smoke command>" \\
908
+ --exit-code 0 \\
909
+ --summary "<business result, task id, status, or observable output>" \\
910
+ --artifacts ".agent/logs/<service>/<smoke>.json" \\
911
+ --metadata-json '{"productSmoke":true,"realProductPath":true}'
912
+ \`\`\`
913
+
914
+ ## Assertions
915
+
916
+ - [ ] Request crossed the real product boundary, not only an isolated unit.
917
+ - [ ] Authentication or user identity path was exercised when relevant.
918
+ - [ ] Persistence/storage/queue side effect was verified when relevant.
919
+ - [ ] Async task or eventual state was polled to terminal status when relevant.
920
+ - [ ] Failure output is specific enough to diagnose the failing layer.
921
+ - [ ] Runtime artifacts are ignored or deliberately promoted according to resource governance.
911
922
  `;
912
923
  }
913
924
  function planTemplate() {
914
- return `# Plan
915
-
916
- ## Approach
917
-
918
- TBD
919
-
920
- ## Boundaries
921
-
922
- TBD
923
-
924
- ## Exception Contract
925
-
926
- 1. TBD
927
- 2. TBD
928
- 3. TBD
929
-
930
- ## Rollback Plan
931
-
932
- TBD
933
-
934
- ## Human Confirmation
935
-
936
- - Required for L/CRITICAL tasks:
937
- - Confirmation source:
938
- - Execution boundary approved:
939
-
940
- ## Test Strategy
941
- TBD
925
+ return `# Plan
926
+
927
+ ## Approach
928
+
929
+ TBD
930
+
931
+ ## Boundaries
932
+
933
+ TBD
934
+
935
+ ## Exception Contract
936
+
937
+ 1. TBD
938
+ 2. TBD
939
+ 3. TBD
940
+
941
+ ## Rollback Plan
942
+
943
+ TBD
944
+
945
+ ## Human Confirmation
946
+
947
+ - Required for L/CRITICAL tasks:
948
+ - Confirmation source:
949
+ - Execution boundary approved:
950
+
951
+ ## Test Strategy
952
+ TBD
942
953
  `;
943
954
  }
944
955
  function verificationTemplate() {
945
- return `# Verification
946
-
947
- ## Commands Run
948
-
949
- | Command | Result | Notes |
950
- | --- | --- | --- |
951
- | | | |
952
-
953
- ## Output Summary
954
-
955
- TBD
956
-
957
- ## Failures And Fixes
958
-
959
- TBD
960
-
961
- ## Final Status
962
- TBD
956
+ return `# Verification
957
+
958
+ ## Commands Run
959
+
960
+ | Command | Result | Notes |
961
+ | --- | --- | --- |
962
+ | | | |
963
+
964
+ ## Output Summary
965
+
966
+ TBD
967
+
968
+ ## Failures And Fixes
969
+
970
+ TBD
971
+
972
+ ## Final Status
973
+ TBD
963
974
  `;
964
975
  }
965
976
  function reviewTemplate() {
966
- return `# Review
967
-
968
- ## Code Review
969
-
970
- TBD
971
-
972
- ## Security Review
973
-
974
- TBD
975
-
976
- ## Same-Pattern Scan
977
-
978
- TBD
979
-
980
- ## Residual Risks
981
- TBD
977
+ return `# Review
978
+
979
+ ## Code Review
980
+
981
+ TBD
982
+
983
+ ## Security Review
984
+
985
+ TBD
986
+
987
+ ## Same-Pattern Scan
988
+
989
+ TBD
990
+
991
+ ## Residual Risks
992
+ TBD
982
993
  `;
983
994
  }
984
995
  function summaryTemplate() {
985
- return `# Summary
986
-
987
- ## Delivered Changes
988
-
989
- TBD
990
-
991
- ## Remaining Risks
992
-
993
- TBD
994
-
995
- ## Follow-Ups
996
-
997
- TBD
998
-
999
- ## Metric Row
1000
-
1001
- | Date | Task | Level | Services | Files Changed | First Verification Pass | Fix Iterations | Artifact Complete | Residual Risk | Final Gate |
1002
- | --- | --- | --- | --- | ---: | --- | ---: | --- | --- | --- |
1003
- | | | | | | | | | | |
996
+ return `# Summary
997
+
998
+ ## Delivered Changes
999
+
1000
+ TBD
1001
+
1002
+ ## Remaining Risks
1003
+
1004
+ TBD
1005
+
1006
+ ## Follow-Ups
1007
+
1008
+ TBD
1009
+
1010
+ ## Metric Row
1011
+
1012
+ | Date | Task | Level | Services | Files Changed | First Verification Pass | Fix Iterations | Artifact Complete | Residual Risk | Final Gate |
1013
+ | --- | --- | --- | --- | ---: | --- | ---: | --- | --- | --- |
1014
+ | | | | | | | | | | |
1004
1015
  `;
1005
1016
  }
1006
1017
  function metricsTemplate() {
1007
- return `# Workflow Metrics
1008
-
1009
- <!-- SCALE_METRICS:START -->
1010
- | Date | Task | Level | Services | Files Changed | First Verification Pass | Fix Iterations | Rework Needed | Artifact Complete | Residual Risk | Final Gate |
1011
- | --- | --- | --- | --- | ---: | --- | ---: | --- | --- | --- | --- |
1012
- | | | | | | | | | | | |
1013
- <!-- SCALE_METRICS:END -->
1014
-
1015
- ## Monthly Review
1016
-
1017
- ### Repeated Failure Patterns
1018
-
1019
- TBD
1020
-
1021
- ### Slowest Gates
1022
-
1023
- TBD
1024
-
1025
- ### Documentation Gaps
1026
-
1027
- TBD
1028
-
1029
- ### Product Design Misses
1030
-
1031
- TBD
1032
-
1033
- ### Proposed Workflow Changes
1034
- TBD
1018
+ return `# Workflow Metrics
1019
+
1020
+ <!-- SCALE_METRICS:START -->
1021
+ | Date | Task | Level | Services | Files Changed | First Verification Pass | Fix Iterations | Rework Needed | Artifact Complete | Residual Risk | Final Gate |
1022
+ | --- | --- | --- | --- | ---: | --- | ---: | --- | --- | --- | --- |
1023
+ | | | | | | | | | | | |
1024
+ <!-- SCALE_METRICS:END -->
1025
+
1026
+ ## Monthly Review
1027
+
1028
+ ### Repeated Failure Patterns
1029
+
1030
+ TBD
1031
+
1032
+ ### Slowest Gates
1033
+
1034
+ TBD
1035
+
1036
+ ### Documentation Gaps
1037
+
1038
+ TBD
1039
+
1040
+ ### Product Design Misses
1041
+
1042
+ TBD
1043
+
1044
+ ### Proposed Workflow Changes
1045
+ TBD
1035
1046
  `;
1036
1047
  }
1037
1048
  function verificationMatrixTemplate(mode, options = {}) {
@@ -1094,132 +1105,132 @@ function productSmokeConfigTemplate(mode) {
1094
1105
  }, null, 2) + '\n';
1095
1106
  }
1096
1107
  function productSmokePowerShellScript() {
1097
- return `# Product smoke probe runner generated by scale-engine.
1098
- $ErrorActionPreference = "Stop"
1099
-
1100
- $Root = (Resolve-Path (Join-Path $PSScriptRoot "..\\..")).Path
1101
- $ConfigPath = Join-Path $Root ".scale\\product-smoke.json"
1102
- $LogDir = Join-Path $Root ".agent\\logs"
1103
- $LogPath = Join-Path $LogDir "product-smoke.json"
1104
-
1105
- New-Item -ItemType Directory -Force -Path $LogDir | Out-Null
1106
-
1107
- $NodeProgram = @'
1108
- ${productSmokeNodeProgram()}
1109
- '@
1110
-
1111
- $TempFile = [System.IO.Path]::GetTempFileName() + ".js"
1112
- Set-Content -Path $TempFile -Value $NodeProgram -Encoding UTF8
1113
- try {
1114
- node $TempFile $ConfigPath $LogPath
1115
- exit $LASTEXITCODE
1116
- } finally {
1117
- Remove-Item -Force $TempFile -ErrorAction SilentlyContinue
1118
- }
1108
+ return `# Product smoke probe runner generated by scale-engine.
1109
+ $ErrorActionPreference = "Stop"
1110
+
1111
+ $Root = (Resolve-Path (Join-Path $PSScriptRoot "..\\..")).Path
1112
+ $ConfigPath = Join-Path $Root ".scale\\product-smoke.json"
1113
+ $LogDir = Join-Path $Root ".agent\\logs"
1114
+ $LogPath = Join-Path $LogDir "product-smoke.json"
1115
+
1116
+ New-Item -ItemType Directory -Force -Path $LogDir | Out-Null
1117
+
1118
+ $NodeProgram = @'
1119
+ ${productSmokeNodeProgram()}
1120
+ '@
1121
+
1122
+ $TempFile = [System.IO.Path]::GetTempFileName() + ".js"
1123
+ Set-Content -Path $TempFile -Value $NodeProgram -Encoding UTF8
1124
+ try {
1125
+ node $TempFile $ConfigPath $LogPath
1126
+ exit $LASTEXITCODE
1127
+ } finally {
1128
+ Remove-Item -Force $TempFile -ErrorAction SilentlyContinue
1129
+ }
1119
1130
  `;
1120
1131
  }
1121
1132
  function productSmokeShellScript() {
1122
- return `#!/usr/bin/env sh
1123
- set -eu
1124
-
1125
- ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
1126
- CONFIG_PATH="$ROOT/.scale/product-smoke.json"
1127
- LOG_DIR="$ROOT/.agent/logs"
1128
- LOG_PATH="$LOG_DIR/product-smoke.json"
1129
-
1130
- mkdir -p "$LOG_DIR"
1131
-
1132
- node - "$CONFIG_PATH" "$LOG_PATH" <<'NODE'
1133
- ${productSmokeNodeProgram()}
1134
- NODE
1133
+ return `#!/usr/bin/env sh
1134
+ set -eu
1135
+
1136
+ ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
1137
+ CONFIG_PATH="$ROOT/.scale/product-smoke.json"
1138
+ LOG_DIR="$ROOT/.agent/logs"
1139
+ LOG_PATH="$LOG_DIR/product-smoke.json"
1140
+
1141
+ mkdir -p "$LOG_DIR"
1142
+
1143
+ node - "$CONFIG_PATH" "$LOG_PATH" <<'NODE'
1144
+ ${productSmokeNodeProgram()}
1145
+ NODE
1135
1146
  `;
1136
1147
  }
1137
1148
  function productSmokeNodeProgram() {
1138
- return `const fs = require('fs');
1139
- const cp = require('child_process');
1140
- const path = require('path');
1141
-
1142
- const configPath = process.argv[2];
1143
- const logPath = process.argv[3];
1144
-
1145
- function writeReport(report) {
1146
- fs.mkdirSync(path.dirname(logPath), { recursive: true });
1147
- fs.writeFileSync(logPath, JSON.stringify(report, null, 2) + '\\n', 'utf8');
1148
- process.stdout.write(JSON.stringify(report, null, 2) + '\\n');
1149
- }
1150
-
1151
- if (!fs.existsSync(configPath)) {
1152
- writeReport({
1153
- version: 1,
1154
- status: 'failed',
1155
- verifiedAt: new Date().toISOString(),
1156
- message: 'Missing .scale/product-smoke.json',
1157
- results: []
1158
- });
1159
- process.exit(1);
1160
- }
1161
-
1162
- const config = JSON.parse(fs.readFileSync(configPath, 'utf8').replace(/^\\uFEFF/, ''));
1163
- const probes = Array.isArray(config.probes) ? config.probes.filter(probe => probe && probe.enabled === true) : [];
1164
-
1165
- if (probes.length === 0) {
1166
- const status = config.emptyProbeBehavior === 'block' ? 'failed' : 'skipped';
1167
- writeReport({
1168
- version: 1,
1169
- status,
1170
- verifiedAt: new Date().toISOString(),
1171
- message: 'No enabled product smoke probes. Enable probes in .scale/product-smoke.json after defining the real product path.',
1172
- results: []
1173
- });
1174
- process.exit(status === 'failed' ? 1 : 0);
1175
- }
1176
-
1177
- const results = probes.map((probe) => {
1178
- const startedAt = new Date().toISOString();
1179
- const expectedExitCode = Number.isInteger(probe.expected && probe.expected.exitCode) ? probe.expected.exitCode : 0;
1180
- const command = String(probe.command || '');
1181
- if (!command.trim()) {
1182
- return {
1183
- id: String(probe.id || 'unnamed-probe'),
1184
- description: String(probe.description || ''),
1185
- command,
1186
- expectedExitCode,
1187
- exitCode: 1,
1188
- status: 'failed',
1189
- startedAt,
1190
- endedAt: new Date().toISOString(),
1191
- outputTail: 'Probe command is empty'
1192
- };
1193
- }
1194
- const result = cp.spawnSync(command, {
1195
- cwd: process.cwd(),
1196
- shell: true,
1197
- encoding: 'utf8',
1198
- timeout: Number(config.timeoutMs || 180000)
1199
- });
1200
- const output = String(result.stdout || '') + String(result.stderr || '') + String(result.error ? result.error.message : '');
1201
- const exitCode = typeof result.status === 'number' ? result.status : 1;
1202
- return {
1203
- id: String(probe.id || 'unnamed-probe'),
1204
- description: String(probe.description || ''),
1205
- command,
1206
- expectedExitCode,
1207
- exitCode,
1208
- status: exitCode === expectedExitCode ? 'passed' : 'failed',
1209
- startedAt,
1210
- endedAt: new Date().toISOString(),
1211
- outputTail: output.length > 2000 ? output.slice(-2000) : output
1212
- };
1213
- });
1214
-
1215
- const failed = results.filter(result => result.status !== 'passed');
1216
- writeReport({
1217
- version: 1,
1218
- status: failed.length === 0 ? 'passed' : 'failed',
1219
- verifiedAt: new Date().toISOString(),
1220
- results
1221
- });
1222
- process.exit(failed.length === 0 ? 0 : 1);
1149
+ return `const fs = require('fs');
1150
+ const cp = require('child_process');
1151
+ const path = require('path');
1152
+
1153
+ const configPath = process.argv[2];
1154
+ const logPath = process.argv[3];
1155
+
1156
+ function writeReport(report) {
1157
+ fs.mkdirSync(path.dirname(logPath), { recursive: true });
1158
+ fs.writeFileSync(logPath, JSON.stringify(report, null, 2) + '\\n', 'utf8');
1159
+ process.stdout.write(JSON.stringify(report, null, 2) + '\\n');
1160
+ }
1161
+
1162
+ if (!fs.existsSync(configPath)) {
1163
+ writeReport({
1164
+ version: 1,
1165
+ status: 'failed',
1166
+ verifiedAt: new Date().toISOString(),
1167
+ message: 'Missing .scale/product-smoke.json',
1168
+ results: []
1169
+ });
1170
+ process.exit(1);
1171
+ }
1172
+
1173
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf8').replace(/^\\uFEFF/, ''));
1174
+ const probes = Array.isArray(config.probes) ? config.probes.filter(probe => probe && probe.enabled === true) : [];
1175
+
1176
+ if (probes.length === 0) {
1177
+ const status = config.emptyProbeBehavior === 'block' ? 'failed' : 'skipped';
1178
+ writeReport({
1179
+ version: 1,
1180
+ status,
1181
+ verifiedAt: new Date().toISOString(),
1182
+ message: 'No enabled product smoke probes. Enable probes in .scale/product-smoke.json after defining the real product path.',
1183
+ results: []
1184
+ });
1185
+ process.exit(status === 'failed' ? 1 : 0);
1186
+ }
1187
+
1188
+ const results = probes.map((probe) => {
1189
+ const startedAt = new Date().toISOString();
1190
+ const expectedExitCode = Number.isInteger(probe.expected && probe.expected.exitCode) ? probe.expected.exitCode : 0;
1191
+ const command = String(probe.command || '');
1192
+ if (!command.trim()) {
1193
+ return {
1194
+ id: String(probe.id || 'unnamed-probe'),
1195
+ description: String(probe.description || ''),
1196
+ command,
1197
+ expectedExitCode,
1198
+ exitCode: 1,
1199
+ status: 'failed',
1200
+ startedAt,
1201
+ endedAt: new Date().toISOString(),
1202
+ outputTail: 'Probe command is empty'
1203
+ };
1204
+ }
1205
+ const result = cp.spawnSync(command, {
1206
+ cwd: process.cwd(),
1207
+ shell: true,
1208
+ encoding: 'utf8',
1209
+ timeout: Number(config.timeoutMs || 180000)
1210
+ });
1211
+ const output = String(result.stdout || '') + String(result.stderr || '') + String(result.error ? result.error.message : '');
1212
+ const exitCode = typeof result.status === 'number' ? result.status : 1;
1213
+ return {
1214
+ id: String(probe.id || 'unnamed-probe'),
1215
+ description: String(probe.description || ''),
1216
+ command,
1217
+ expectedExitCode,
1218
+ exitCode,
1219
+ status: exitCode === expectedExitCode ? 'passed' : 'failed',
1220
+ startedAt,
1221
+ endedAt: new Date().toISOString(),
1222
+ outputTail: output.length > 2000 ? output.slice(-2000) : output
1223
+ };
1224
+ });
1225
+
1226
+ const failed = results.filter(result => result.status !== 'passed');
1227
+ writeReport({
1228
+ version: 1,
1229
+ status: failed.length === 0 ? 'passed' : 'failed',
1230
+ verifiedAt: new Date().toISOString(),
1231
+ results
1232
+ });
1233
+ process.exit(failed.length === 0 ? 0 : 1);
1223
1234
  `;
1224
1235
  }
1225
1236
  function packageVersion() {
@@ -1232,49 +1243,49 @@ function packageVersion() {
1232
1243
  }
1233
1244
  }
1234
1245
  function githubActionsPreflightTemplate() {
1235
- return `name: SCALE Preflight
1236
-
1237
- on:
1238
- pull_request:
1239
- push:
1240
- branches:
1241
- - main
1242
- - master
1243
-
1244
- jobs:
1245
- preflight:
1246
- runs-on: ubuntu-latest
1247
- steps:
1248
- - name: Checkout
1249
- uses: actions/checkout@v4
1250
-
1251
- - name: Setup Node.js
1252
- uses: actions/setup-node@v4
1253
- with:
1254
- node-version: '20'
1255
-
1256
- - name: Install project dependencies when present
1257
- shell: bash
1258
- run: |
1259
- if [ -f package-lock.json ]; then
1260
- npm ci
1261
- elif [ -f package.json ]; then
1262
- npm install
1263
- fi
1264
-
1265
- - name: Run SCALE preflight
1266
- run: npx @hongmaple0820/scale-engine@latest preflight --service all --preflight-profile ci
1246
+ return `name: SCALE Preflight
1247
+
1248
+ on:
1249
+ pull_request:
1250
+ push:
1251
+ branches:
1252
+ - main
1253
+ - master
1254
+
1255
+ jobs:
1256
+ preflight:
1257
+ runs-on: ubuntu-latest
1258
+ steps:
1259
+ - name: Checkout
1260
+ uses: actions/checkout@v4
1261
+
1262
+ - name: Setup Node.js
1263
+ uses: actions/setup-node@v4
1264
+ with:
1265
+ node-version: '20'
1266
+
1267
+ - name: Install project dependencies when present
1268
+ shell: bash
1269
+ run: |
1270
+ if [ -f package-lock.json ]; then
1271
+ npm ci
1272
+ elif [ -f package.json ]; then
1273
+ npm install
1274
+ fi
1275
+
1276
+ - name: Run SCALE preflight
1277
+ run: npx @hongmaple0820/scale-engine@latest preflight --service all --preflight-profile ci
1267
1278
  `;
1268
1279
  }
1269
1280
  function prePushPreflightTemplate() {
1270
- return `#!/usr/bin/env sh
1271
- set -eu
1272
-
1273
- if command -v scale >/dev/null 2>&1; then
1274
- scale preflight --service all
1275
- else
1276
- npx @hongmaple0820/scale-engine@latest preflight --service all
1277
- fi
1281
+ return `#!/usr/bin/env sh
1282
+ set -eu
1283
+
1284
+ if command -v scale >/dev/null 2>&1; then
1285
+ scale preflight --service all
1286
+ else
1287
+ npx @hongmaple0820/scale-engine@latest preflight --service all
1288
+ fi
1278
1289
  `;
1279
1290
  }
1280
1291
  //# sourceMappingURL=GovernanceTemplates.js.map