@ryuenn3123/agentic-senior-core 4.3.15 → 5.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.
Files changed (198) hide show
  1. package/.agents/plugins/marketplace.json +21 -0
  2. package/.agents/rules/agentic-senior-core.md +126 -0
  3. package/.claude-plugin/marketplace.json +17 -0
  4. package/.claude-plugin/plugin.json +17 -0
  5. package/.clinerules/agentic-senior-core.md +94 -0
  6. package/.codex-plugin/plugin.json +24 -0
  7. package/.cursor/rules/agentic-senior-core.mdc +99 -0
  8. package/.devin-plugin/plugin.json +13 -0
  9. package/.github/copilot-instructions.md +94 -0
  10. package/.github/plugin/marketplace.json +20 -0
  11. package/.github/plugin/plugin.json +16 -0
  12. package/.kiro/steering/agentic-senior-core.md +94 -0
  13. package/.openclaw/skills/asc/SKILL.md +23 -0
  14. package/.openclaw/skills/asc-audit/SKILL.md +28 -0
  15. package/.openclaw/skills/asc-review/SKILL.md +54 -0
  16. package/.opencode/plugins/agentic-senior-core.mjs +31 -0
  17. package/.windsurf/rules/agentic-senior-core.md +94 -0
  18. package/AGENTS.md +126 -179
  19. package/CONTRIBUTING.md +93 -63
  20. package/README.md +160 -111
  21. package/__init__.py +61 -0
  22. package/bin/agentic-senior-core.js +41 -43
  23. package/commands/asc-audit.md +1 -0
  24. package/commands/asc-audit.toml +2 -0
  25. package/commands/asc-help.md +9 -0
  26. package/commands/asc-help.toml +2 -0
  27. package/commands/asc-refactor.md +1 -0
  28. package/commands/asc-refactor.toml +2 -0
  29. package/commands/asc-review.md +1 -0
  30. package/commands/asc-review.toml +2 -0
  31. package/gemini-extension.json +10 -0
  32. package/hooks/copilot-hooks.json +21 -0
  33. package/hooks/hooks.json +31 -0
  34. package/hooks/session-start.js +36 -0
  35. package/hooks/subagent-start.js +38 -0
  36. package/lib/cli/commands/adapter.mjs +109 -0
  37. package/lib/cli/commands/clean.mjs +63 -0
  38. package/lib/cli/commands/status.mjs +94 -0
  39. package/package.json +43 -67
  40. package/plugin.yaml +16 -0
  41. package/scripts/uninstall.js +38 -0
  42. package/skills/asc/SKILL.md +16 -0
  43. package/skills/asc-audit/SKILL.md +28 -0
  44. package/skills/asc-refactor/SKILL.md +35 -0
  45. package/skills/asc-review/SKILL.md +54 -0
  46. package/.agent-context/policies/llm-judge-threshold.json +0 -29
  47. package/.agent-context/prompts/bootstrap-design.md +0 -63
  48. package/.agent-context/prompts/compact-natural-mode.md +0 -100
  49. package/.agent-context/prompts/init-project.md +0 -60
  50. package/.agent-context/prompts/refactor.md +0 -38
  51. package/.agent-context/prompts/review-code.md +0 -31
  52. package/.agent-context/review-checklists/architecture-review.md +0 -57
  53. package/.agent-context/review-checklists/pr-checklist.md +0 -136
  54. package/.agent-context/rules/api-docs.md +0 -24
  55. package/.agent-context/rules/api-versioning.md +0 -16
  56. package/.agent-context/rules/architecture.md +0 -33
  57. package/.agent-context/rules/background-jobs.md +0 -17
  58. package/.agent-context/rules/config-and-flags.md +0 -16
  59. package/.agent-context/rules/database-design.md +0 -18
  60. package/.agent-context/rules/docker-runtime.md +0 -17
  61. package/.agent-context/rules/error-handling.md +0 -16
  62. package/.agent-context/rules/event-driven.md +0 -16
  63. package/.agent-context/rules/frontend-architecture.md +0 -54
  64. package/.agent-context/rules/microservices.md +0 -16
  65. package/.agent-context/rules/migrations.md +0 -16
  66. package/.agent-context/rules/observability.md +0 -16
  67. package/.agent-context/rules/performance.md +0 -16
  68. package/.agent-context/rules/realtime.md +0 -16
  69. package/.agent-context/rules/resilience.md +0 -18
  70. package/.agent-context/rules/security.md +0 -18
  71. package/.agent-context/rules/testing.md +0 -16
  72. package/.agent-context/state/README.md +0 -25
  73. package/.agent-context/state/architecture-map.md +0 -40
  74. package/.agent-context/state/benchmark-comparison-schema.json +0 -181
  75. package/.agent-context/state/benchmark-reproducibility.json +0 -87
  76. package/.agent-context/state/benchmark-thresholds.json +0 -10
  77. package/.agent-context/state/benchmark-writer-judge-config.json +0 -58
  78. package/.agent-context/state/dependency-map.md +0 -41
  79. package/.agent-context/state/memory-adapter-contract.json +0 -52
  80. package/.agent-context/state/memory-schema-v1.json +0 -88
  81. package/GEMINI.md +0 -1
  82. package/benchmarks/README.md +0 -60
  83. package/benchmarks/compact-natural-mode/fixtures.mjs +0 -359
  84. package/benchmarks/compact-natural-mode/scorer.mjs +0 -331
  85. package/benchmarks/runtime-token-saver/fixtures.mjs +0 -836
  86. package/lib/cli/adaptive-context/catalog.mjs +0 -390
  87. package/lib/cli/adaptive-context/file-signals.mjs +0 -100
  88. package/lib/cli/adaptive-context/implications.mjs +0 -44
  89. package/lib/cli/adaptive-context.mjs +0 -365
  90. package/lib/cli/audits/typography-palette-anti-repeat/color-utils.mjs +0 -156
  91. package/lib/cli/audits/typography-palette-anti-repeat/file-scanner.mjs +0 -103
  92. package/lib/cli/audits/typography-palette-anti-repeat/typography-utils.mjs +0 -70
  93. package/lib/cli/audits/typography-palette-anti-repeat-audit.mjs +0 -239
  94. package/lib/cli/backup.mjs +0 -210
  95. package/lib/cli/commands/audit-design-anti-repeat.mjs +0 -39
  96. package/lib/cli/commands/context.mjs +0 -140
  97. package/lib/cli/commands/init/project-context.mjs +0 -60
  98. package/lib/cli/commands/init/runtime-environment.mjs +0 -59
  99. package/lib/cli/commands/init/setup-decisions.mjs +0 -83
  100. package/lib/cli/commands/init.mjs +0 -654
  101. package/lib/cli/commands/launch.mjs +0 -76
  102. package/lib/cli/commands/optimize.mjs +0 -284
  103. package/lib/cli/commands/rollback.mjs +0 -64
  104. package/lib/cli/commands/upgrade/token-optimization-state.mjs +0 -51
  105. package/lib/cli/commands/upgrade.mjs +0 -451
  106. package/lib/cli/compiler.mjs +0 -570
  107. package/lib/cli/constants.mjs +0 -136
  108. package/lib/cli/detector/constants.mjs +0 -135
  109. package/lib/cli/detector/design-evidence/collector.mjs +0 -256
  110. package/lib/cli/detector/design-evidence/constants.mjs +0 -39
  111. package/lib/cli/detector/design-evidence/file-traversal.mjs +0 -83
  112. package/lib/cli/detector/design-evidence/structured-attribute-evidence.mjs +0 -117
  113. package/lib/cli/detector/design-evidence/summary.mjs +0 -109
  114. package/lib/cli/detector/design-evidence/utility-helpers.mjs +0 -122
  115. package/lib/cli/detector/design-evidence.mjs +0 -25
  116. package/lib/cli/detector/stack-detection.mjs +0 -243
  117. package/lib/cli/detector/ui-signals.mjs +0 -150
  118. package/lib/cli/detector/workspace-scan.mjs +0 -177
  119. package/lib/cli/detector.mjs +0 -23
  120. package/lib/cli/init-detection-flow.mjs +0 -48
  121. package/lib/cli/init-options.mjs +0 -237
  122. package/lib/cli/init-selection.mjs +0 -29
  123. package/lib/cli/memory-continuity.mjs +0 -537
  124. package/lib/cli/preflight.mjs +0 -76
  125. package/lib/cli/project-scaffolder/constants.mjs +0 -69
  126. package/lib/cli/project-scaffolder/discovery.mjs +0 -272
  127. package/lib/cli/project-scaffolder/prompt-builders.mjs +0 -171
  128. package/lib/cli/project-scaffolder/storage.mjs +0 -144
  129. package/lib/cli/project-scaffolder/ui-scope-detection.mjs +0 -36
  130. package/lib/cli/project-scaffolder.mjs +0 -29
  131. package/lib/cli/rollback.mjs +0 -66
  132. package/lib/cli/token-optimization.mjs +0 -486
  133. package/lib/cli/utils/filesystem.mjs +0 -81
  134. package/lib/cli/utils/managed-surface.mjs +0 -280
  135. package/lib/cli/utils/prompting.mjs +0 -44
  136. package/lib/cli/utils.mjs +0 -479
  137. package/mcp.json +0 -134
  138. package/scripts/adaptive-context/fixtures.mjs +0 -183
  139. package/scripts/adaptive-context-benchmark.mjs +0 -9
  140. package/scripts/ascx-runtime-token-saver-benchmark.mjs +0 -9
  141. package/scripts/audit-cache-layer-contract.mjs +0 -263
  142. package/scripts/audit-caching-scope-hygiene.mjs +0 -268
  143. package/scripts/audit-file-size.mjs +0 -219
  144. package/scripts/audit-reflection-citations.mjs +0 -163
  145. package/scripts/audit-release-bundle.mjs +0 -170
  146. package/scripts/audit-rule-id-uniqueness.mjs +0 -313
  147. package/scripts/audit-typography-palette-anti-repeat.mjs +0 -120
  148. package/scripts/benchmark-evidence-bundle.mjs +0 -645
  149. package/scripts/benchmark-gate.mjs +0 -121
  150. package/scripts/benchmark-intelligence.mjs +0 -33
  151. package/scripts/benchmark-writer-judge-matrix.mjs +0 -379
  152. package/scripts/build-release-benchmark-bundle.mjs +0 -202
  153. package/scripts/bump-version.mjs +0 -103
  154. package/scripts/clean-local-artifacts.mjs +0 -78
  155. package/scripts/compact-natural-mode-benchmark.mjs +0 -9
  156. package/scripts/context-triggered-audit.mjs +0 -391
  157. package/scripts/detection-benchmark.mjs +0 -127
  158. package/scripts/docs-quality-drift-report.mjs +0 -358
  159. package/scripts/documentation-boundary-audit.mjs +0 -305
  160. package/scripts/explain-on-demand-audit.mjs +0 -427
  161. package/scripts/forbidden-content-check.mjs +0 -123
  162. package/scripts/frontend-usability-audit.mjs +0 -243
  163. package/scripts/generate-sbom.mjs +0 -61
  164. package/scripts/governance-weekly-report.mjs +0 -466
  165. package/scripts/llm-judge/checklist-loader.mjs +0 -45
  166. package/scripts/llm-judge/constants.mjs +0 -66
  167. package/scripts/llm-judge/diff-collection.mjs +0 -74
  168. package/scripts/llm-judge/prompting.mjs +0 -78
  169. package/scripts/llm-judge/providers.mjs +0 -111
  170. package/scripts/llm-judge/verdict.mjs +0 -134
  171. package/scripts/llm-judge.mjs +0 -200
  172. package/scripts/memory-continuity-benchmark.mjs +0 -322
  173. package/scripts/quality-trend-report.mjs +0 -289
  174. package/scripts/release-gate/audit-checks.mjs +0 -441
  175. package/scripts/release-gate/constants.mjs +0 -53
  176. package/scripts/release-gate/runtime.mjs +0 -63
  177. package/scripts/release-gate/static-checks.mjs +0 -182
  178. package/scripts/release-gate.mjs +0 -42
  179. package/scripts/rules-guardian-audit.mjs +0 -580
  180. package/scripts/single-source-lazy-loading-audit.mjs +0 -449
  181. package/scripts/sync-thin-adapters.mjs +0 -72
  182. package/scripts/token-optimization-benchmark.mjs +0 -252
  183. package/scripts/ui-design-judge/constants.mjs +0 -13
  184. package/scripts/ui-design-judge/design-execution-summary.mjs +0 -81
  185. package/scripts/ui-design-judge/git-input.mjs +0 -134
  186. package/scripts/ui-design-judge/prompting.mjs +0 -52
  187. package/scripts/ui-design-judge/providers.mjs +0 -102
  188. package/scripts/ui-design-judge/reporting.mjs +0 -183
  189. package/scripts/ui-design-judge/rubric-calibration.mjs +0 -214
  190. package/scripts/ui-design-judge/rubric-goldset.json +0 -188
  191. package/scripts/ui-design-judge.mjs +0 -319
  192. package/scripts/ui-rubric-calibration.mjs +0 -35
  193. package/scripts/validate/config.mjs +0 -519
  194. package/scripts/validate/coverage-checks.mjs +0 -446
  195. package/scripts/validate/file-structure.mjs +0 -162
  196. package/scripts/validate/markdown-content.mjs +0 -109
  197. package/scripts/validate/project-metadata.mjs +0 -166
  198. package/scripts/validate.mjs +0 -338
@@ -1,570 +0,0 @@
1
- // @file-size-exception: Multiple compilation passes (rule + state + adapter); planned for split in Phase 1 compiler refactor.
2
- /**
3
- * Context Compiler — Rulebook compilation and state persistence.
4
- * Depends on: constants.mjs, utils.mjs
5
- */
6
- import fs from 'node:fs/promises';
7
- import path from 'node:path';
8
-
9
- import {
10
- CLI_VERSION,
11
- POLICY_FILE_NAME,
12
- AGENT_DECISION_STACK_FILE_NAME,
13
- AGENT_DECISION_BLUEPRINT_FILE_NAME,
14
- } from './constants.mjs';
15
-
16
- import {
17
- pathExists,
18
- collectFileNames,
19
- } from './utils.mjs';
20
-
21
- import {
22
- readTokenOptimizationState,
23
- buildTokenOptimizationGuidanceBlock,
24
- } from './token-optimization.mjs';
25
- import {
26
- readMemoryContinuityState,
27
- buildMemoryContinuityGuidanceBlock,
28
- } from './memory-continuity.mjs';
29
-
30
- function toSingleLine(value, fallbackValue) {
31
- const normalizedValue = String(value || '').replace(/\s+/g, ' ').trim();
32
- return normalizedValue || fallbackValue;
33
- }
34
-
35
- function buildAnchorCommitmentHeader(designIntent) {
36
- return null;
37
- }
38
-
39
- function buildContainerizationStrategySnapshot(dockerStrategy) {
40
- const selectedDockerStrategy = String(dockerStrategy || '').trim();
41
- const normalizedDockerStrategy = selectedDockerStrategy.toLowerCase();
42
- const dockerSelected = Boolean(selectedDockerStrategy) && !normalizedDockerStrategy.startsWith('no docker');
43
- const developmentRequired = dockerSelected
44
- && (normalizedDockerStrategy.includes('development') || normalizedDockerStrategy.includes('both'));
45
- const productionRequired = dockerSelected
46
- && (normalizedDockerStrategy.includes('production') || normalizedDockerStrategy.includes('both'));
47
-
48
- return {
49
- selected: selectedDockerStrategy || null,
50
- developmentRequired,
51
- productionRequired,
52
- materializationRequired: dockerSelected,
53
- requiredRuleFile: dockerSelected ? '.agent-context/rules/docker-runtime.md' : null,
54
- commandExecutionPolicy: dockerSelected
55
- ? 'author-files-first-run-docker-commands-only-when-requested-or-approved'
56
- : null,
57
- };
58
- }
59
-
60
- export async function writeSelectedPolicy(targetDirectoryPath, selectedProfileName) {
61
- const policyFilePath = path.join(targetDirectoryPath, '.agent-context', 'policies', POLICY_FILE_NAME);
62
- const parsedPolicy = JSON.parse(await fs.readFile(policyFilePath, 'utf8'));
63
- parsedPolicy.selectedProfile = selectedProfileName;
64
- await fs.writeFile(policyFilePath, JSON.stringify(parsedPolicy, null, 2) + '\n', 'utf8');
65
- }
66
-
67
- export async function writeOnboardingReport({
68
- targetDirectoryPath,
69
- selectedProfileName,
70
- selectedPreset,
71
- projectScope = null,
72
- projectTopology = null,
73
- selectedStackFileName,
74
- selectedAdditionalStackFileNames = [],
75
- selectedBlueprintFileName,
76
- selectedAdditionalBlueprintFileNames = [],
77
- includeCiGuardrails,
78
- localOnly = false,
79
- setupDurationMs,
80
- projectDetection,
81
- runtimeEnvironment = null,
82
- dockerStrategy = null,
83
- operationMode = 'init',
84
- tokenOptimization = undefined,
85
- memoryContinuity = undefined,
86
- detectionTransparency = null,
87
- uiScopeSignals = null,
88
- }) {
89
- const hasExplicitRuntimeDecision = selectedStackFileName && selectedStackFileName !== AGENT_DECISION_STACK_FILE_NAME;
90
- const hasExplicitArchitectureDecision = selectedBlueprintFileName && selectedBlueprintFileName !== AGENT_DECISION_BLUEPRINT_FILE_NAME;
91
- const onboardingReportPath = path.join(targetDirectoryPath, '.agent-context', 'state', 'onboarding-report.json');
92
- const resolvedTokenOptimization = typeof tokenOptimization === 'undefined'
93
- ? await readTokenOptimizationState(targetDirectoryPath)
94
- : tokenOptimization;
95
- const resolvedMemoryContinuity = typeof memoryContinuity === 'undefined'
96
- ? await readMemoryContinuityState(targetDirectoryPath)
97
- : memoryContinuity;
98
- const onboardingReport = {
99
- cliVersion: CLI_VERSION,
100
- generatedAt: new Date().toISOString(),
101
- operationMode,
102
- selectedProfile: selectedProfileName,
103
- selectedPreset,
104
- projectScope,
105
- projectTopology,
106
- runtimeDecision: {
107
- mode: hasExplicitRuntimeDecision ? 'explicit-constraint' : 'agent-decision-required',
108
- explicitStack: hasExplicitRuntimeDecision ? selectedStackFileName : null,
109
- detectedStackEvidence: projectDetection.detectedStackFileName || null,
110
- detectedAdditionalStackEvidence: projectDetection.secondaryStackFileNames || [],
111
- },
112
- architectureDecision: {
113
- mode: hasExplicitArchitectureDecision ? 'explicit-constraint' : 'agent-decision-required',
114
- explicitBlueprint: hasExplicitArchitectureDecision ? selectedBlueprintFileName : null,
115
- detectedBlueprintEvidence: projectDetection.detectedBlueprintFileName || null,
116
- },
117
- selectedStack: hasExplicitRuntimeDecision ? selectedStackFileName : null,
118
- selectedAdditionalStacks: hasExplicitRuntimeDecision ? selectedAdditionalStackFileNames : [],
119
- selectedBlueprint: hasExplicitArchitectureDecision ? selectedBlueprintFileName : null,
120
- selectedAdditionalBlueprints: hasExplicitArchitectureDecision ? selectedAdditionalBlueprintFileNames : [],
121
- ruleLoadingPolicy: {
122
- canonicalSource: 'AGENTS.md',
123
- stackLoadingMode: 'lazy',
124
- domainRuleLoadingMode: 'lazy',
125
- loadedOnDemand: true,
126
- primaryStack: hasExplicitRuntimeDecision ? selectedStackFileName : null,
127
- additionalStacks: hasExplicitRuntimeDecision ? selectedAdditionalStackFileNames : [],
128
- agentDecisionRequired: !hasExplicitRuntimeDecision,
129
- },
130
- ciGuardrailsEnabled: includeCiGuardrails,
131
- localOnly,
132
- setupDurationMs,
133
- runtimeEnvironment,
134
- containerizationStrategy: buildContainerizationStrategySnapshot(dockerStrategy),
135
- tokenOptimization: resolvedTokenOptimization,
136
- memoryContinuity: resolvedMemoryContinuity,
137
- responseCompression: {
138
- enabled: true,
139
- mode: 'compact-natural-mode',
140
- defaultOn: true,
141
- promptFile: '.agent-context/prompts/compact-natural-mode.md',
142
- appliesTo: 'agent-final-responses',
143
- commandOutputBoundary: 'ASCX handles command-output compression separately',
144
- },
145
- autoDetection: {
146
- detectedStack: projectDetection.detectedStackFileName,
147
- detectedAdditionalStacks: projectDetection.secondaryStackFileNames || [],
148
- detectedBlueprint: projectDetection.detectedBlueprintFileName,
149
- detectedAdditionalBlueprints: [],
150
- confidenceLabel: projectDetection.confidenceLabel,
151
- confidenceScore: projectDetection.confidenceScore,
152
- confidenceGap: projectDetection.confidenceGap,
153
- detectionReasoning: projectDetection.detectionReasoning,
154
- rankedCandidates: projectDetection.rankedCandidates,
155
- evidence: projectDetection.evidence,
156
- detectionTransparency: detectionTransparency || null,
157
- uiScope: uiScopeSignals
158
- ? {
159
- isUiScopeLikely: uiScopeSignals.isUiScopeLikely === true,
160
- signalReasons: uiScopeSignals.signalReasons || [],
161
- workspaceUiEntries: uiScopeSignals.workspaceUiEntries || [],
162
- frontendEvidenceMetrics: uiScopeSignals.frontendEvidenceMetrics || null,
163
- designEvidenceSummary: uiScopeSignals.designEvidenceSummary || null,
164
- }
165
- : null,
166
- },
167
- };
168
-
169
- await fs.writeFile(onboardingReportPath, JSON.stringify(onboardingReport, null, 2) + '\n', 'utf8');
170
- }
171
-
172
- export async function loadOnboardingReportIfExists(targetDirectoryPath) {
173
- const onboardingReportPath = path.join(targetDirectoryPath, '.agent-context', 'state', 'onboarding-report.json');
174
- if (!(await pathExists(onboardingReportPath))) {
175
- return null;
176
- }
177
-
178
- const onboardingReportContent = await fs.readFile(onboardingReportPath, 'utf8');
179
- return JSON.parse(onboardingReportContent);
180
- }
181
-
182
- export async function buildCompiledRulesContent({
183
- targetDirectoryPath,
184
- selectedStackFileName,
185
- selectedAdditionalStackFileNames = [],
186
- selectedBlueprintFileName,
187
- selectedAdditionalBlueprintFileNames = [],
188
- includeCiGuardrails,
189
- }) {
190
- const resolvedTargetDirectoryPath = path.resolve(targetDirectoryPath);
191
- const selectedRulesDirectoryPath = path.join(resolvedTargetDirectoryPath, '.agent-context', 'rules');
192
- const selectedStacksDirectoryPath = path.join(resolvedTargetDirectoryPath, '.agent-context', 'stacks');
193
- const selectedBlueprintsDirectoryPath = path.join(resolvedTargetDirectoryPath, '.agent-context', 'blueprints');
194
- const normalizedAdditionalStackFileNames = Array.isArray(selectedAdditionalStackFileNames)
195
- ? Array.from(new Set(selectedAdditionalStackFileNames.filter((stackFileName) => stackFileName && stackFileName !== selectedStackFileName)))
196
- : [];
197
- const normalizedAdditionalBlueprintFileNames = Array.isArray(selectedAdditionalBlueprintFileNames)
198
- ? Array.from(new Set(selectedAdditionalBlueprintFileNames.filter(
199
- (blueprintFileName) => blueprintFileName && blueprintFileName !== selectedBlueprintFileName
200
- )))
201
- : [];
202
-
203
- const universalRuleFileNames = await collectFileNames(selectedRulesDirectoryPath);
204
- const availableStackProfileFileNames = new Set(await collectFileNames(selectedStacksDirectoryPath));
205
- const availableBlueprintProfileFileNames = new Set(await collectFileNames(selectedBlueprintsDirectoryPath));
206
- const contextBlocks = [];
207
- const hasExplicitRuntimeDecision = selectedStackFileName && selectedStackFileName !== AGENT_DECISION_STACK_FILE_NAME;
208
- const hasExplicitArchitectureDecision = selectedBlueprintFileName && selectedBlueprintFileName !== AGENT_DECISION_BLUEPRINT_FILE_NAME;
209
-
210
- function firstMarkdownHeading(content, fallbackLabel) {
211
- const headingLine = content
212
- .split(/\r?\n/)
213
- .find((line) => line.trim().startsWith('#'));
214
-
215
- if (!headingLine) {
216
- return fallbackLabel;
217
- }
218
-
219
- return headingLine.replace(/^#+\s*/, '').trim();
220
- }
221
-
222
- function humanizeProfileName(fileName) {
223
- return String(fileName || '')
224
- .replace(/\.md$/i, '')
225
- .replace(/[-_]/g, ' ')
226
- .trim();
227
- }
228
-
229
- contextBlocks.push(
230
- [
231
- '## BOOTSTRAP CHAIN (MANDATORY)',
232
- 'Resolve the smallest relevant layer set before responding. Do not eagerly load unrelated layers:',
233
- '1. .agent-context/rules/',
234
- '2. Resolve runtime and architecture signals from project context, repo evidence, and live research.',
235
- '3. .agent-context/prompts/',
236
- '4. Dynamic runtime and architecture decision signals (from project context + research evidence)',
237
- '5. .agent-context/state/',
238
- `6. .agent-context/policies/${POLICY_FILE_NAME}`,
239
- '7. docs/ project context (or bootstrap prompts when docs are not materialized)',
240
- '',
241
- 'Canonical instruction source: AGENTS.md',
242
- 'Native import bridges: CLAUDE.md, GEMINI.md',
243
- 'Managed rule library: .agent-context/',
244
- 'Project decisions and dynamic state: .agent-context/state/onboarding-report.json',
245
- ].join('\n')
246
- );
247
-
248
- contextBlocks.push(
249
- [
250
- '## LAYER 1: RULES (SCOPE-RESOLVED)',
251
- 'Available rule files under .agent-context/rules/:',
252
- ...universalRuleFileNames.map((universalRuleFileName, index) => `${index + 1}. .agent-context/rules/${universalRuleFileName}`),
253
- '',
254
- 'Resolution policy: load only the rule files relevant to the current task and prioritize data safety and API contract integrity first, then writing polish.',
255
- ].join('\n')
256
- );
257
-
258
- if (hasExplicitRuntimeDecision) {
259
- const stackFilePath = path.join(selectedStacksDirectoryPath, selectedStackFileName);
260
- const hasStackProfileFile = availableStackProfileFileNames.has(selectedStackFileName);
261
- const stackSummary = hasStackProfileFile
262
- ? firstMarkdownHeading(await fs.readFile(stackFilePath, 'utf8'), selectedStackFileName)
263
- : `Explicit runtime constraint for ${humanizeProfileName(selectedStackFileName)}.`;
264
- contextBlocks.push(
265
- [
266
- `## LAYER 2: RUNTIME CONSTRAINT (${selectedStackFileName})`,
267
- hasStackProfileFile
268
- ? `Source: stack-profile:${selectedStackFileName}`
269
- : 'Source: explicit user constraint',
270
- `Summary: ${stackSummary}`,
271
- 'Use this only as a constraint when the task touches that runtime. Do not treat it as design direction.',
272
- ].join('\n')
273
- );
274
- } else {
275
- contextBlocks.push(
276
- [
277
- '## LAYER 2: RUNTIME DECISION REQUIRED',
278
- 'No runtime stack was selected by the user.',
279
- 'For a fresh project, the first implementation step is to ask the AI agent to recommend a runtime/framework from the brief, constraints, and live official documentation.',
280
- 'For an existing project, inspect repo markers and current files directly before editing. Detection evidence is not a migration instruction.',
281
- 'Do not silently choose a stack from offline defaults.',
282
- ].join('\n')
283
- );
284
- }
285
-
286
- if (hasExplicitRuntimeDecision && normalizedAdditionalStackFileNames.length > 0) {
287
- contextBlocks.push(
288
- [
289
- '## LAYER 2B: ADDITIONAL RUNTIME EVIDENCE',
290
- 'This project has multiple runtime constraints. Load additional runtime evidence below only when the task touches that runtime:',
291
- ...normalizedAdditionalStackFileNames.map((stackFileName, stackIndex) => {
292
- if (availableStackProfileFileNames.has(stackFileName)) {
293
- return `${stackIndex + 1}. stack-profile:${stackFileName}`;
294
- }
295
-
296
- return `${stackIndex + 1}. ${stackFileName} (runtime evidence signal)`;
297
- }),
298
- ].join('\n')
299
- );
300
- }
301
-
302
- contextBlocks.push(
303
- [
304
- '## LAYER 2 POLICY: LAZY RULE LOADING',
305
- hasExplicitRuntimeDecision
306
- ? `Primary runtime constraint: ${selectedStackFileName}`
307
- : 'Primary runtime constraint: unresolved until agent recommendation is approved',
308
- normalizedAdditionalStackFileNames.length > 0
309
- ? `Additional runtime evidence loads on demand: ${normalizedAdditionalStackFileNames.map((stackFileName) => {
310
- if (availableStackProfileFileNames.has(stackFileName)) {
311
- return `stack-profile:${stackFileName}`;
312
- }
313
-
314
- return `${stackFileName} (runtime evidence signal)`;
315
- }).join(', ')}`
316
- : 'No stack-specific governance adapter is loaded by default.',
317
- 'Load global domain rules only when task scope touches that domain.',
318
- 'Avoid eager loading unrelated runtime or domain guidance to prevent instruction conflicts.',
319
- ].join('\n')
320
- );
321
-
322
- contextBlocks.push(
323
- [
324
- '## LAYER 5: EXECUTION PROMPTS AND UI TRIGGERS',
325
- 'Load these prompt contracts only when their trigger matches the user request:',
326
- 'Default. .agent-context/prompts/compact-natural-mode.md -> final response shape and evidence-preserving compact prose',
327
- '0. Documentation-first mode -> docs, documentation, dokumen, docs/*, architecture docs, flow docs, API docs, lengkapkan docs',
328
- '1. .agent-context/prompts/init-project.md -> create, build, new project, scaffold',
329
- '2. .agent-context/prompts/refactor.md -> refactor, improve, clean up, fix',
330
- '3. .agent-context/prompts/review-code.md -> review, audit, check, analyze',
331
- '4. .agent-context/prompts/bootstrap-design.md -> ui, ux, layout, screen, tailwind, frontend, redesign',
332
- 'Documentation-first policy:',
333
- '- Create or refine required project docs before implementation: README.md for every fresh or existing project; docs/doc-index.md whenever docs/ exists; docs/project-brief.md; docs/architecture-decision-record.md; docs/flow-overview.md; docs/api-contract.md when APIs, firmware endpoints, CLI commands, or web application flows exist; docs/database-schema.md when persistent data exists; and docs/DESIGN.md for UI scope.',
334
- '- Keep README.md public and developer friendly, including for private projects: explain what the project is, who it is for, setup, usage, configuration, and links to deeper docs. Do not put secrets, internal agent notes, private reasoning, or governance policy dumps in it.',
335
- '- Use docs/doc-index.md as the compact read-routing map before selecting deeper docs. Do not broad-read docs/*.md by default.',
336
- '- Add PRD, SRS, technical-design, or separate ERD only when project evidence justifies them.',
337
- '- Keep docs complete but compact. Add extra docs files only for stable, distinct, or long workflows such as hardware setup, deployment, operations, testing validation, or troubleshooting.',
338
- '- Write formal project docs in English by default unless the user explicitly asks for another documentation language.',
339
- '- For docs-only/docs-first requests, do not write application, firmware, or UI code until the user asks or approves an implementation plan.',
340
- 'UI trigger policy:',
341
- '- Load .agent-context/prompts/bootstrap-design.md and .agent-context/rules/frontend-architecture.md first.',
342
- '- Follow the three-step design direction process in bootstrap-design.md: name defaults, choose anchor, commit to creative direction.',
343
- ].join('\n')
344
- );
345
-
346
- if (hasExplicitArchitectureDecision) {
347
- const blueprintFilePath = path.join(selectedBlueprintsDirectoryPath, selectedBlueprintFileName);
348
- const hasBlueprintProfileFile = availableBlueprintProfileFileNames.has(selectedBlueprintFileName);
349
- const blueprintSummary = hasBlueprintProfileFile
350
- ? firstMarkdownHeading(await fs.readFile(blueprintFilePath, 'utf8'), selectedBlueprintFileName)
351
- : `Explicit architecture constraint for ${humanizeProfileName(selectedBlueprintFileName)}.`;
352
- contextBlocks.push(
353
- [
354
- `## LAYER 3: ARCHITECTURE CONSTRAINT (${selectedBlueprintFileName})`,
355
- hasBlueprintProfileFile
356
- ? `Source: architecture-profile:${selectedBlueprintFileName}`
357
- : 'Source: explicit user constraint',
358
- `Summary: ${blueprintSummary}`,
359
- 'Use this only as an explicit constraint when scaffolding or changing architecture boundaries.',
360
- ].join('\n')
361
- );
362
- } else {
363
- contextBlocks.push(
364
- [
365
- '## LAYER 3: ARCHITECTURE DECISION REQUIRED',
366
- 'No architecture blueprint was selected by the user.',
367
- 'The AI agent must propose the architecture from the product brief, repo evidence, required docs, and live research before implementation.',
368
- 'Do not map detected runtime markers into a blueprint automatically.',
369
- ].join('\n')
370
- );
371
- }
372
-
373
- if (hasExplicitArchitectureDecision && normalizedAdditionalBlueprintFileNames.length > 0) {
374
- contextBlocks.push(
375
- [
376
- '## LAYER 3A: ADDITIONAL BLUEPRINT PROFILES',
377
- 'This project uses multiple architecture blueprints. Load all additional blueprint profiles below:',
378
- ...normalizedAdditionalBlueprintFileNames.map((blueprintFileName, blueprintIndex) => {
379
- if (availableBlueprintProfileFileNames.has(blueprintFileName)) {
380
- return `${blueprintIndex + 1}. architecture-profile:${blueprintFileName}`;
381
- }
382
-
383
- return `${blueprintIndex + 1}. ${blueprintFileName} (dynamic architecture signal)`;
384
- }),
385
- ].join('\n')
386
- );
387
- }
388
-
389
- if (includeCiGuardrails) {
390
- const ciBlueprintEntries = ['ci-github-actions.md', 'ci-gitlab.md'].map((ciBlueprintFileName, ciBlueprintIndex) => {
391
- if (availableBlueprintProfileFileNames.has(ciBlueprintFileName)) {
392
- return `${ciBlueprintIndex + 1}. architecture-profile:${ciBlueprintFileName}`;
393
- }
394
-
395
- return `${ciBlueprintIndex + 1}. ${ciBlueprintFileName} (dynamic CI policy signal)`;
396
- });
397
-
398
- contextBlocks.push(
399
- [
400
- '## LAYER 3B: CI/CD GUARDRAILS',
401
- 'Load these CI blueprints when pipeline or release logic is touched:',
402
- ...ciBlueprintEntries,
403
- ].join('\n')
404
- );
405
- }
406
-
407
- const tokenOptimizationState = await readTokenOptimizationState(resolvedTargetDirectoryPath);
408
- if (tokenOptimizationState?.enabled) {
409
- contextBlocks.push(
410
- `## TOKEN OPTIMIZATION PROFILE\nSource: .agent-context/state/token-optimization.json\n\n${buildTokenOptimizationGuidanceBlock(tokenOptimizationState).trim()}`
411
- );
412
- }
413
-
414
- const memoryContinuityState = await readMemoryContinuityState(resolvedTargetDirectoryPath);
415
- if (memoryContinuityState?.enabled) {
416
- contextBlocks.push(
417
- `## MEMORY CONTINUITY PROFILE\nSource: .agent-context/state/memory-continuity.json\n\n${buildMemoryContinuityGuidanceBlock(memoryContinuityState).trim()}`
418
- );
419
- }
420
-
421
- contextBlocks.push(
422
- [
423
- '## LAYER 7: STATE AWARENESS (MANDATORY)',
424
- 'Load these files before touching critical paths:',
425
- '1. .agent-context/state/architecture-map.md',
426
- '2. .agent-context/state/dependency-map.md',
427
- 'Use these maps to prevent unsafe cross-module changes.',
428
- ].join('\n')
429
- );
430
- contextBlocks.push(
431
- [
432
- '## REVIEW CHECKLISTS (MANDATORY)',
433
- '1. .agent-context/review-checklists/pr-checklist.md',
434
- '2. .agent-context/review-checklists/architecture-review.md',
435
- 'Security and performance checks are consolidated inside these two checklist files.',
436
- 'Do not claim done before checklist pass.',
437
- ].join('\n')
438
- );
439
-
440
- const projectBriefPath = path.join(resolvedTargetDirectoryPath, 'docs', 'project-brief.md');
441
- const bootstrapProjectContextPromptPath = path.join(
442
- resolvedTargetDirectoryPath,
443
- '.agent-context',
444
- 'prompts',
445
- 'bootstrap-project-context.md'
446
- );
447
- const bootstrapDesignPromptPath = path.join(
448
- resolvedTargetDirectoryPath,
449
- '.agent-context',
450
- 'prompts',
451
- 'bootstrap-design.md'
452
- );
453
- const hasBootstrapProjectContextPrompt = await pathExists(bootstrapProjectContextPromptPath);
454
- const hasBootstrapDesignPrompt = await pathExists(bootstrapDesignPromptPath);
455
-
456
- if (await pathExists(projectBriefPath)) {
457
- const hasRootReadme = await pathExists(path.join(resolvedTargetDirectoryPath, 'README.md'));
458
- const projectDocsEntries = [];
459
- const candidateDocFileNames = [
460
- 'doc-index.md',
461
- 'project-brief.md',
462
- 'architecture-decision-record.md',
463
- 'technical-design.md',
464
- 'prd.md',
465
- 'srs.md',
466
- 'database-schema.md',
467
- 'erd.md',
468
- 'api-contract.md',
469
- 'flow-overview.md',
470
- 'DESIGN.md',
471
- 'runbook.md',
472
- 'troubleshooting.md',
473
- ];
474
-
475
- for (const candidateFileName of candidateDocFileNames) {
476
- const candidateFilePath = path.join(resolvedTargetDirectoryPath, 'docs', candidateFileName);
477
- if (await pathExists(candidateFilePath)) {
478
- projectDocsEntries.push(candidateFileName);
479
- }
480
- }
481
-
482
- contextBlocks.push(
483
- [
484
- '## LAYER 9: PROJECT CONTEXT (MANDATORY)',
485
- 'These documents describe the specific project being built.',
486
- 'Read them before writing any application code:',
487
- ...(hasRootReadme ? ['1. README.md'] : []),
488
- ...projectDocsEntries.map((docFileName, docIndex) => `${(hasRootReadme ? 2 : 1) + docIndex}. docs/${docFileName}`),
489
- '',
490
- 'Universal SOP hard block policy:',
491
- '- README.md must exist and read as a public and developer entrypoint.',
492
- '- docs/doc-index.md must exist whenever docs/ exists and act as the compact read-routing map.',
493
- '- Stop implementation if docs/project-brief.md is missing.',
494
- '- Stop implementation if docs/architecture-decision-record.md (alias: docs/Architecture-Decision-Record.md) is missing.',
495
- '- Stop implementation if docs/flow-overview.md is missing.',
496
- '- If the product uses persistent data, docs/database-schema.md must exist before coding continues.',
497
- '- If the product exposes API or web application flows, docs/api-contract.md must exist before coding continues.',
498
- '- For UI scope, stop implementation if docs/DESIGN.md is missing.',
499
- '- Keep README.md overview-level, public, and developer friendly; do not put secrets, internal agent notes, private reasoning, or governance policy dumps in it.',
500
- '- Use README.md plus docs/doc-index.md to choose the smallest relevant read set before loading deeper docs.',
501
- '- Add PRD, SRS, technical-design, or separate ERD only when project evidence justifies them.',
502
- '- Materialize missing docs first, then continue coding.',
503
- '- Bootstrap missing docs from real repo evidence and the latest user request. Do not write generic placeholder templates.',
504
- '- Separate confirmed facts from assumptions and end each major explanation with the next validation action.',
505
- '',
506
- 'These docs were generated during project initialization and reflect the architecture,',
507
- 'database design, API contracts, and application flows chosen for this project.',
508
- 'Latest user prompt defines current feature scope and product direction.',
509
- 'Treat requested features as dynamic, but keep stack/database/auth constraints consistent',
510
- 'with project docs unless the user explicitly asks for a migration.',
511
- 'When scope changes, implement the new request and update README.md plus docs/* in the same change when documented context changes',
512
- 'so generated context stays aligned with the codebase.',
513
- 'Update them as the project evolves. They are living references, not frozen specs.',
514
- ].join('\n')
515
- );
516
- } else if (hasBootstrapProjectContextPrompt) {
517
- const bootstrapPromptEntries = [
518
- '.agent-context/prompts/bootstrap-project-context.md',
519
- ];
520
-
521
- if (hasBootstrapDesignPrompt) {
522
- bootstrapPromptEntries.push('.agent-context/prompts/bootstrap-design.md');
523
- }
524
-
525
- contextBlocks.push(
526
- [
527
- '## LAYER 9: PROJECT CONTEXT (MANDATORY)',
528
- 'Project docs are not materialized yet. Bootstrap them before writing application code.',
529
- 'Execute these prompts in your IDE assistant first:',
530
- ...bootstrapPromptEntries.map((promptFilePath, promptIndex) => `${promptIndex + 1}. ${promptFilePath}`),
531
- '',
532
- 'Bootstrap policy:',
533
- '- Create README.md as a public and developer entrypoint before coding continues.',
534
- '- Create docs/doc-index.md as the compact read-routing map whenever docs/ exists.',
535
- '- Hard block: do not write application code until docs/project-brief.md and docs/architecture-decision-record.md exist.',
536
- '- docs/flow-overview.md must also exist before coding continues.',
537
- '- Add docs/database-schema.md when persistent data is involved.',
538
- '- Add docs/api-contract.md when API or web application flows are involved.',
539
- '- Add PRD, SRS, technical-design, or separate ERD only when project evidence justifies them.',
540
- '- For docs-only/docs-first requests, stop after docs unless the user asks for implementation or approves an implementation plan.',
541
- '- If docs/project-brief.md is missing, execute bootstrap-project-context prompt immediately.',
542
- hasBootstrapDesignPrompt
543
- ? '- For UI scope: if docs/DESIGN.md is missing, execute bootstrap-design prompt before implementing UI surfaces.'
544
- : '- For UI scope: add a design bootstrap prompt before implementing UI surfaces.',
545
- '- Bootstrap docs from repo evidence and the latest user request. Do not use generic placeholder templates.',
546
- '- Separate confirmed facts from assumptions, include an Assumptions to Validate section when context is incomplete, and end with the next validation action.',
547
- '- Save generated docs under docs/ and keep them updated when feature scope changes.',
548
- 'Latest user prompt defines current feature scope and product direction.',
549
- 'Treat synthesized docs as living references, then continue implementation with those docs as source of truth.',
550
- ].join('\n')
551
- );
552
- }
553
-
554
-
555
- return [
556
- '# AGENTIC-SENIOR-CORE DYNAMIC GOVERNANCE RULESET',
557
- '',
558
- `Generated by Agentic-Senior-Core CLI v${CLI_VERSION}`,
559
- `Timestamp: ${new Date().toISOString()}`,
560
- `Selected policy file: .agent-context/policies/${POLICY_FILE_NAME}`,
561
- '',
562
- '## GOVERNANCE PRECEDENCE',
563
- '1. Follow AGENTS.md as the primary source.',
564
- '2. Use architecture-map.md and dependency-map.md as change safety boundaries.',
565
- '3. Enforce pr-checklist.md before declaring completion.',
566
- '',
567
- ...contextBlocks,
568
- '',
569
- ].join('\n');
570
- }