@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,451 +0,0 @@
1
- /**
2
- * Upgrade Command — Governance upgrade assistant.
3
- * Depends on: constants, utils, detector, compiler
4
- */
5
- import { createInterface } from 'node:readline/promises';
6
- import { stdin, stdout } from 'node:process';
7
- import fs from 'node:fs/promises';
8
- import path from 'node:path';
9
-
10
- import {
11
- CLI_VERSION,
12
- AGENT_CONTEXT_DIR,
13
- PROFILE_PRESETS,
14
- AGENT_DECISION_STACK_FILE_NAME,
15
- AGENT_DECISION_BLUEPRINT_FILE_NAME,
16
- } from '../constants.mjs';
17
-
18
- import {
19
- ensureDirectory,
20
- askYesNo,
21
- toTitleCase,
22
- collectFileNames,
23
- formatDuration,
24
- pathExists,
25
- analyzeManagedGovernanceSurface,
26
- copyGovernanceAssetsToTarget,
27
- } from '../utils.mjs';
28
-
29
- import {
30
- detectProjectContext,
31
- buildDetectionSummary,
32
- formatDetectionCandidates,
33
- detectUiScopeSignals,
34
- } from '../detector.mjs';
35
- import {
36
- writeSelectedPolicy,
37
- writeOnboardingReport,
38
- loadOnboardingReportIfExists,
39
- } from '../compiler.mjs';
40
-
41
- import { runPreflightChecks } from '../preflight.mjs';
42
- import {
43
- createBackup,
44
- ensureBackupGitignoreEntry,
45
- ensureRuntimeArtifactGitignoreEntries,
46
- } from '../backup.mjs';
47
- import { performRollback } from '../rollback.mjs';
48
- import { detectProjectDocTemplateStaleness } from '../project-scaffolder.mjs';
49
- import { ensureActiveMemorySnapshot } from '../memory-continuity.mjs';
50
- import { buildExistingProjectMajorConstraints } from '../init-detection-flow.mjs';
51
- import {
52
- applyUpgradeTokenOptimizationPlan,
53
- resolveUpgradeTokenOptimizationPlan,
54
- } from './upgrade/token-optimization-state.mjs';
55
-
56
- export function parseUpgradeArguments(commandArguments) {
57
- const parsedUpgradeOptions = {
58
- targetDirectory: '.',
59
- dryRun: false,
60
- skipConfirmation: false,
61
- includeMcpTemplate: false,
62
- pruneManagedSurface: true,
63
- };
64
-
65
- for (let argumentIndex = 0; argumentIndex < commandArguments.length; argumentIndex++) {
66
- const currentArgument = commandArguments[argumentIndex];
67
-
68
- if (!currentArgument.startsWith('--')) {
69
- parsedUpgradeOptions.targetDirectory = currentArgument;
70
- continue;
71
- }
72
-
73
- if (currentArgument === '--dry-run') {
74
- parsedUpgradeOptions.dryRun = true;
75
- continue;
76
- }
77
-
78
- if (currentArgument === '--yes') {
79
- parsedUpgradeOptions.skipConfirmation = true;
80
- continue;
81
- }
82
-
83
- if (currentArgument === '--mcp-template') {
84
- parsedUpgradeOptions.includeMcpTemplate = true;
85
- continue;
86
- }
87
-
88
- if (currentArgument === '--no-mcp-template') {
89
- parsedUpgradeOptions.includeMcpTemplate = false;
90
- continue;
91
- }
92
-
93
- if (currentArgument === '--prune') {
94
- parsedUpgradeOptions.pruneManagedSurface = true;
95
- continue;
96
- }
97
-
98
- if (currentArgument === '--no-prune') {
99
- parsedUpgradeOptions.pruneManagedSurface = false;
100
- continue;
101
- }
102
-
103
- throw new Error(`Unknown option: ${currentArgument}`);
104
- }
105
-
106
- return parsedUpgradeOptions;
107
- }
108
-
109
- export async function runUpgradeCommand(targetDirectoryArgument, upgradeOptions = {}) {
110
- const resolvedTargetDirectoryPath = path.resolve(targetDirectoryArgument || '.');
111
-
112
- if (resolvedTargetDirectoryPath.toLowerCase() === 'c:\\windows' || resolvedTargetDirectoryPath.toLowerCase() === 'c:\\windows\\system32') {
113
- console.error('\n[FATAL] Target directory resolved to a Windows system folder (C:\\Windows).');
114
- console.error('If you are running Windows npm from inside WSL, this is caused by cmd.exe lacking UNC path support.');
115
- console.error('Please install and use a native Linux Node.js/npm directly inside WSL to setup your project.');
116
- process.exit(1);
117
- }
118
-
119
- const setupStartedAt = Date.now();
120
- await ensureDirectory(resolvedTargetDirectoryPath);
121
-
122
- const preflightResult = await runPreflightChecks(resolvedTargetDirectoryPath, 'upgrade');
123
- if (!preflightResult.passed) {
124
- console.error('\n[FATAL] Preflight checks failed. Upgrading here would cause errors or data loss:');
125
- console.error(JSON.stringify(preflightResult, null, 2));
126
- throw new Error('Preflight checks failed.');
127
- }
128
-
129
- const userInterface = createInterface({ input: stdin, output: stdout });
130
-
131
- try {
132
- console.log(`\nAgentic-Senior-Core CLI v${CLI_VERSION}`);
133
- console.log('Running managed guidance upgrade for an existing repository.');
134
-
135
- const managedSurfacePlan = await analyzeManagedGovernanceSurface(resolvedTargetDirectoryPath, {
136
- includeMcpTemplate: upgradeOptions.includeMcpTemplate === true,
137
- });
138
-
139
- const stackFileNames = await collectFileNames(path.join(AGENT_CONTEXT_DIR, 'stacks'));
140
- const blueprintFileNames = await collectFileNames(path.join(AGENT_CONTEXT_DIR, 'blueprints'));
141
- const existingOnboardingReport = await loadOnboardingReportIfExists(resolvedTargetDirectoryPath);
142
- const tokenOptimizationPlan = await resolveUpgradeTokenOptimizationPlan(
143
- resolvedTargetDirectoryPath,
144
- existingOnboardingReport
145
- );
146
- const projectDetection = await detectProjectContext(resolvedTargetDirectoryPath);
147
- const selectedProfileName = PROFILE_PRESETS[existingOnboardingReport?.selectedProfile]
148
- ? existingOnboardingReport.selectedProfile
149
- : 'balanced';
150
-
151
- const hasExplicitRuntimeConstraint = existingOnboardingReport?.runtimeDecision?.mode === 'explicit-constraint';
152
- const hasExplicitArchitectureConstraint = existingOnboardingReport?.architectureDecision?.mode === 'explicit-constraint';
153
-
154
- const selectedStackFileName = hasExplicitRuntimeConstraint && stackFileNames.includes(existingOnboardingReport?.selectedStack)
155
- ? existingOnboardingReport.selectedStack
156
- : AGENT_DECISION_STACK_FILE_NAME;
157
-
158
- const selectedAdditionalStackFileNames = hasExplicitRuntimeConstraint && Array.isArray(existingOnboardingReport?.selectedAdditionalStacks)
159
- ? Array.from(new Set(existingOnboardingReport.selectedAdditionalStacks.filter(
160
- (stackFileName) => stackFileNames.includes(stackFileName) && stackFileName !== selectedStackFileName
161
- )))
162
- : [];
163
-
164
- const selectedBlueprintFileName = hasExplicitArchitectureConstraint && blueprintFileNames.includes(existingOnboardingReport?.selectedBlueprint)
165
- ? existingOnboardingReport.selectedBlueprint
166
- : AGENT_DECISION_BLUEPRINT_FILE_NAME;
167
-
168
- const selectedAdditionalBlueprintFileNames = hasExplicitArchitectureConstraint && Array.isArray(existingOnboardingReport?.selectedAdditionalBlueprints)
169
- ? Array.from(new Set(existingOnboardingReport.selectedAdditionalBlueprints.filter(
170
- (blueprintFileName) => blueprintFileNames.includes(blueprintFileName) && blueprintFileName !== selectedBlueprintFileName
171
- )))
172
- : [];
173
-
174
- const includeCiGuardrails = typeof existingOnboardingReport?.ciGuardrailsEnabled === 'boolean'
175
- ? existingOnboardingReport.ciGuardrailsEnabled
176
- : true;
177
- const uiScopeSignals = await detectUiScopeSignals({
178
- targetDirectoryPath: resolvedTargetDirectoryPath,
179
- selectedStackFileName,
180
- selectedBlueprintFileName,
181
- projectScopeKey: existingOnboardingReport?.projectScope?.key || null,
182
- projectScopeSourceLabel: 'onboarding project scope',
183
- });
184
- const packageManifest = uiScopeSignals.packageManifest;
185
- const designContractPaths = ['docs/DESIGN.md'];
186
- const missingDesignContractPaths = [];
187
-
188
- for (const designContractPath of designContractPaths) {
189
- const absoluteDesignContractPath = path.join(resolvedTargetDirectoryPath, ...designContractPath.split('/'));
190
- if (!(await pathExists(absoluteDesignContractPath))) {
191
- missingDesignContractPaths.push(designContractPath);
192
- }
193
- }
194
-
195
- const detectionMajorConstraints = buildExistingProjectMajorConstraints({ mode: 'upgrade' });
196
- const detectionTransparency = {
197
- declaredAt: new Date().toISOString(),
198
- declarationType: 'existing-project',
199
- declarationShown: true,
200
- detectionSummary: buildDetectionSummary(projectDetection),
201
- activeRulesSummary: {
202
- canonicalSource: 'AGENTS.md',
203
- compiledRulebook: null,
204
- legacyThinAdapters: [],
205
- generatedBridgeAdapters: ['CLAUDE.md', 'GEMINI.md'],
206
- stackLoadingMode: 'lazy',
207
- domainRuleLoadingMode: 'lazy',
208
- selectedProfile: selectedProfileName,
209
- selectedProfileDisplayName: toTitleCase(selectedProfileName),
210
- blockingSeverities: PROFILE_PRESETS[selectedProfileName]?.blockingSeverities || [],
211
- ciGuardrailsEnabled: includeCiGuardrails,
212
- },
213
- majorConstraints: detectionMajorConstraints,
214
- quickConfirmation: {
215
- offered: false,
216
- response: 'upgrade-auto',
217
- source: 'upgrade-assistant',
218
- },
219
- decision: {
220
- mode: 'upgrade-auto',
221
- selectedStackFileName,
222
- selectedBlueprintFileName,
223
- },
224
- };
225
-
226
- console.log('\nExisting project detection transparency:');
227
- if (projectDetection.detectedStackFileName) {
228
- const confidenceScoreLabel = Number(projectDetection.confidenceScore || 0).toFixed(2);
229
- console.log(
230
- `- Detected stack: ${toTitleCase(projectDetection.detectedStackFileName)} (${projectDetection.confidenceLabel}, score ${confidenceScoreLabel})`
231
- );
232
- } else {
233
- console.log('- Detected stack: unresolved (insufficient markers).');
234
- }
235
- console.log('- Active rules baseline: canonical AGENTS.md + .agent-context/ lazy rule library');
236
- console.log(
237
- `- Active review thresholds: ${(
238
- PROFILE_PRESETS[selectedProfileName]?.blockingSeverities || []
239
- ).join(', ') || 'none'})`
240
- );
241
- console.log('- Top candidates:');
242
- console.log(formatDetectionCandidates(projectDetection.rankedCandidates));
243
- console.log('- Major constraints:');
244
- for (const majorConstraint of detectionMajorConstraints) {
245
- console.log(` - ${majorConstraint}`);
246
- }
247
-
248
- const projectDocStalenessReport = await detectProjectDocTemplateStaleness(resolvedTargetDirectoryPath);
249
-
250
- console.log('\nUpgrade preview:');
251
- console.log(`- Target directory: ${resolvedTargetDirectoryPath}`);
252
- console.log(`- Runtime decision: ${selectedStackFileName === AGENT_DECISION_STACK_FILE_NAME ? 'agent recommendation required from repo evidence' : toTitleCase(selectedStackFileName)}`);
253
- if (selectedAdditionalStackFileNames.length > 0) {
254
- console.log(`- Additional stacks: ${selectedAdditionalStackFileNames.map((stackFileName) => toTitleCase(stackFileName)).join(', ')}`);
255
- }
256
- console.log(`- Architecture decision: ${selectedBlueprintFileName === AGENT_DECISION_BLUEPRINT_FILE_NAME ? 'agent recommendation required from repo evidence' : toTitleCase(selectedBlueprintFileName)}`);
257
- if (selectedAdditionalBlueprintFileNames.length > 0) {
258
- console.log(`- Additional blueprints: ${selectedAdditionalBlueprintFileNames.map((blueprintFileName) => toTitleCase(blueprintFileName)).join(', ')}`);
259
- }
260
- console.log(`- CI/CD quality checks (guardrails): ${includeCiGuardrails ? 'enabled' : 'disabled'}`);
261
- console.log('- Instruction surface: AGENTS.md canonical with CLAUDE.md and GEMINI.md import bridges');
262
- console.log('- Default activation cues: Adaptive Context bootstrap, ASCX wrappers, Compact Natural replies');
263
- console.log(`- Token optimization policy: ${tokenOptimizationPlan.previewLabel}`);
264
- console.log('- Default response mode: Compact Natural Mode enabled');
265
- console.log(`- Managed surface stale files: ${managedSurfacePlan.staleFiles.length}`);
266
- console.log(`- Managed surface stale directories: ${managedSurfacePlan.staleDirectories.length}`);
267
- console.log(`- Managed surface sync mode: 1:1 (prune enabled)`);
268
- console.log(`- Managed surface prune mode: ${upgradeOptions.pruneManagedSurface === true ? 'enabled (default)' : 'disabled (--no-prune)'}`);
269
- console.log(`- MCP config write mode: ${upgradeOptions.includeMcpTemplate === true ? 'enabled (--mcp-template)' : 'disabled (default)'}`);
270
- if (projectDocStalenessReport.hasProjectDocs) {
271
- console.log(`- Project docs detected: ${projectDocStalenessReport.checkedFileNames.length}`);
272
- console.log(`- Project docs expected template version: ${projectDocStalenessReport.expectedTemplateVersion}`);
273
- console.log(`- Project docs stale files: ${projectDocStalenessReport.staleFiles.length}`);
274
- }
275
-
276
- if (managedSurfacePlan.staleFiles.length > 0 || managedSurfacePlan.staleDirectories.length > 0) {
277
- console.log('\nManaged surface stale paths preview (up to 5):');
278
- const previewPaths = [
279
- ...managedSurfacePlan.staleFiles,
280
- ...managedSurfacePlan.staleDirectories,
281
- ].slice(0, 5);
282
- for (const previewPath of previewPaths) {
283
- console.log(`- ${previewPath}`);
284
- }
285
- if (managedSurfacePlan.staleFiles.length + managedSurfacePlan.staleDirectories.length > previewPaths.length) {
286
- console.log('- ...');
287
- }
288
- }
289
-
290
- if (projectDocStalenessReport.staleFiles.length > 0) {
291
- console.log('\n[WARN] Some project docs were generated from older template versions:');
292
- for (const staleDoc of projectDocStalenessReport.staleFiles) {
293
- const detectedVersionLabel = staleDoc.detectedTemplateVersion || 'missing';
294
- console.log(`- docs/${staleDoc.fileName} (detected: ${detectedVersionLabel}, expected: ${projectDocStalenessReport.expectedTemplateVersion})`);
295
- }
296
- console.log('Required action: regenerate docs with init --scaffold-docs or update the files manually to match the latest template version.');
297
- }
298
-
299
- if (uiScopeSignals.isUiScopeLikely && missingDesignContractPaths.length > 0) {
300
- console.log('\n[WARN] UI/frontend scope was detected, but the dynamic design contract is incomplete:');
301
- for (const missingDesignContractPath of missingDesignContractPaths) {
302
- console.log(`- Missing ${missingDesignContractPath}`);
303
- }
304
- if (uiScopeSignals.signalReasons.length > 0) {
305
- console.log(`- Detection signals: ${uiScopeSignals.signalReasons.join('; ')}`);
306
- }
307
- if (Array.isArray(uiScopeSignals.workspaceUiEntries) && uiScopeSignals.workspaceUiEntries.length > 0) {
308
- console.log(`- Nested UI workspaces: ${uiScopeSignals.workspaceUiEntries.map((workspaceUiEntry) => workspaceUiEntry.relativePath).join(', ')}`);
309
- }
310
- console.log('Required action: create or refresh docs/DESIGN.md before allowing UI implementation work.');
311
- console.log('Upgrade synchronizes governance assets, but it does not author project-specific docs/DESIGN.md automatically.');
312
- }
313
-
314
- if (upgradeOptions.dryRun) {
315
- console.log('\nDry run enabled. No files were modified.');
316
- return;
317
- }
318
-
319
- const shouldApplyUpgrade = upgradeOptions.skipConfirmation
320
- ? true
321
- : await askYesNo('Apply upgrade and synchronize managed files?', userInterface, true);
322
-
323
- if (!shouldApplyUpgrade) {
324
- console.log('Upgrade cancelled by user.');
325
- return;
326
- }
327
-
328
- await createBackup(resolvedTargetDirectoryPath);
329
- const backupGitignoreResult = await ensureBackupGitignoreEntry(resolvedTargetDirectoryPath);
330
- if (backupGitignoreResult.status !== 'unchanged') {
331
- console.log(`Local backup artifacts ignored in .gitignore (${backupGitignoreResult.entry}).`);
332
- }
333
- const runtimeArtifactGitignoreResult = await ensureRuntimeArtifactGitignoreEntries(resolvedTargetDirectoryPath);
334
- if (runtimeArtifactGitignoreResult.status !== 'unchanged') {
335
- console.log(
336
- `Local runtime artifacts ignored in .gitignore (${runtimeArtifactGitignoreResult.addedEntries.join(', ')}).`
337
- );
338
- }
339
-
340
- try {
341
- const governanceSyncResult = await copyGovernanceAssetsToTarget(resolvedTargetDirectoryPath, {
342
- includeMcpTemplate: upgradeOptions.includeMcpTemplate === true,
343
- pruneManagedSurface: upgradeOptions.pruneManagedSurface === true,
344
- managedSurfacePlan,
345
- });
346
- const supplementalCreatedFileNames = [];
347
- const shouldEnsureActiveMemorySnapshot = existingOnboardingReport?.memoryContinuity?.enabled !== false;
348
- const tokenOptimizationApplyResult = await applyUpgradeTokenOptimizationPlan(
349
- resolvedTargetDirectoryPath,
350
- tokenOptimizationPlan
351
- );
352
- if (tokenOptimizationApplyResult.createdFileName) {
353
- supplementalCreatedFileNames.push(tokenOptimizationApplyResult.createdFileName);
354
- }
355
-
356
- const obsoleteDesignIntentPath = path.join(resolvedTargetDirectoryPath, 'docs', 'design-intent.json');
357
- if (await pathExists(obsoleteDesignIntentPath)) {
358
- try {
359
- await fs.unlink(obsoleteDesignIntentPath);
360
- supplementalCreatedFileNames.push('docs/design-intent.json (DELETED - Obsolete Compliance Theater)');
361
- console.log('\n[CLEANUP] Removed obsolete docs/design-intent.json. The 2026 Context Ops Paradigm uses plain-text DESIGN.md only.');
362
- } catch (err) {
363
- // ignore error
364
- }
365
- }
366
-
367
- if (shouldEnsureActiveMemorySnapshot) {
368
- const activeMemoryResult = await ensureActiveMemorySnapshot(resolvedTargetDirectoryPath, {
369
- projectName: packageManifest?.name || path.basename(resolvedTargetDirectoryPath),
370
- });
371
-
372
- if (activeMemoryResult.created) {
373
- supplementalCreatedFileNames.push('.agent-context/state/active-memory.json');
374
- }
375
- }
376
-
377
- await writeSelectedPolicy(resolvedTargetDirectoryPath, selectedProfileName);
378
-
379
- const setupDurationMs = Date.now() - setupStartedAt;
380
- await writeOnboardingReport({
381
- targetDirectoryPath: resolvedTargetDirectoryPath,
382
- selectedProfileName,
383
- projectScope: existingOnboardingReport?.projectScope || null,
384
- selectedStackFileName,
385
- selectedAdditionalStackFileNames,
386
- selectedBlueprintFileName,
387
- selectedAdditionalBlueprintFileNames,
388
- includeCiGuardrails,
389
- setupDurationMs,
390
- projectDetection,
391
- runtimeEnvironment: existingOnboardingReport?.runtimeEnvironment || null,
392
- operationMode: 'upgrade',
393
- tokenOptimization: tokenOptimizationApplyResult.reportState,
394
- detectionTransparency,
395
- uiScopeSignals,
396
- });
397
-
398
- console.log('\nUpgrade complete.');
399
- console.log(`- Governance surface sync: 1:1 (${governanceSyncResult.updatedFiles.length} updated, ${governanceSyncResult.createdFiles.length} new, ${governanceSyncResult.deletedManagedFiles.length} deleted, ${governanceSyncResult.unchangedFiles.length} unchanged)`);
400
- const preservedInstructionEntrypoints = Array.from(new Set([
401
- ...(governanceSyncResult.preservedFiles || []),
402
- ])).sort();
403
- if (preservedInstructionEntrypoints.length > 0) {
404
- console.log(`- User-owned instruction entrypoints preserved: ${preservedInstructionEntrypoints.length}`);
405
- }
406
- if (governanceSyncResult.deletedManagedDirectories.length > 0) {
407
- console.log(`- Managed stale directories removed: ${governanceSyncResult.deletedManagedDirectories.length}`);
408
- }
409
- console.log(`- Setup time: ${formatDuration(setupDurationMs)}`);
410
-
411
- const hasDetailedGovernanceChanges = governanceSyncResult.updatedFiles.length > 0
412
- || governanceSyncResult.createdFiles.length > 0
413
- || governanceSyncResult.deletedManagedFiles.length > 0
414
- || preservedInstructionEntrypoints.length > 0;
415
-
416
- if (hasDetailedGovernanceChanges) {
417
- console.log('\nDetailed changes:');
418
- governanceSyncResult.createdFiles.forEach((fileName) => console.log(` [NEW] ${fileName}`));
419
- governanceSyncResult.updatedFiles.forEach((fileName) => console.log(` [UPDATED] ${fileName}`));
420
- governanceSyncResult.deletedManagedFiles.forEach((fileName) => console.log(` [DELETED] ${fileName}`));
421
- preservedInstructionEntrypoints.forEach((fileName) => console.log(` [PRESERVE] ${fileName}`));
422
- }
423
- if (supplementalCreatedFileNames.length > 0) {
424
- if (!hasDetailedGovernanceChanges) {
425
- console.log('\nDetailed changes:');
426
- }
427
- supplementalCreatedFileNames.forEach((fileName) => console.log(` [NEW] ${fileName} (seed)`));
428
- }
429
-
430
- console.log('\nRefreshed files: AGENTS.md, CLAUDE.md, GEMINI.md, .agent-context/, and .agent-context/state/onboarding-report.json');
431
- console.log('Default activation cues remain Adaptive Context bootstrap, ASCX command wrappers, and Compact Natural final replies.');
432
- console.log('Default response mode remains Compact Natural Mode through .agent-context/prompts/compact-natural-mode.md.');
433
-
434
- } catch (error) {
435
- console.error('\n[FATAL] An error occurred during upgrade. Attempting automatic rollback...');
436
- try {
437
- const rollbackReport = await performRollback(resolvedTargetDirectoryPath);
438
- if (rollbackReport.success) {
439
- console.error('[OK] Automatic rollback successful. The directory has been restored.');
440
- } else {
441
- console.error('[WARN] Automatic rollback completed with errors. You may need to manually clean up.');
442
- }
443
- } catch (rbError) {
444
- console.error(`[FATAL] Automatic rollback failed: ${rbError.message}`);
445
- }
446
- throw error;
447
- }
448
- } finally {
449
- userInterface.close();
450
- }
451
- }