@ryuenn3123/agentic-senior-core 3.0.37 → 3.0.39

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 (66) hide show
  1. package/.agent-context/prompts/bootstrap-design.md +109 -146
  2. package/.agent-context/rules/frontend-architecture.md +92 -108
  3. package/.agent-context/state/README.md +26 -0
  4. package/.agent-context/state/architecture-map.md +32 -17
  5. package/.agent-context/state/dependency-map.md +31 -22
  6. package/.cursor/mcp.json +10 -0
  7. package/.cursor/rules/agentic-senior-core.mdc +48 -0
  8. package/.cursorrules +22 -88
  9. package/.gemini/instructions.md +25 -16
  10. package/.github/copilot-instructions.md +25 -16
  11. package/.github/instructions/agentic-senior-core.instructions.md +47 -0
  12. package/.instructions.md +98 -207
  13. package/.windsurf/rules/agentic-senior-core.md +43 -0
  14. package/.windsurfrules +22 -88
  15. package/AGENTS.md +23 -26
  16. package/CLAUDE.md +43 -0
  17. package/CONTRIBUTING.md +7 -2
  18. package/GEMINI.md +43 -0
  19. package/README.md +25 -7
  20. package/lib/cli/backup.mjs +4 -4
  21. package/lib/cli/commands/init/project-context.mjs +101 -0
  22. package/lib/cli/commands/init/runtime-environment.mjs +59 -0
  23. package/lib/cli/commands/init/setup-decisions.mjs +83 -0
  24. package/lib/cli/commands/init.mjs +33 -250
  25. package/lib/cli/commands/optimize.mjs +1 -1
  26. package/lib/cli/commands/upgrade.mjs +34 -16
  27. package/lib/cli/compiler.mjs +59 -17
  28. package/lib/cli/constants.mjs +5 -0
  29. package/lib/cli/detector.mjs +4 -0
  30. package/lib/cli/init-detection-flow.mjs +9 -1
  31. package/lib/cli/init-selection.mjs +0 -5
  32. package/lib/cli/preflight.mjs +3 -3
  33. package/lib/cli/project-scaffolder/design-contract/validation.mjs +789 -0
  34. package/lib/cli/project-scaffolder/design-contract.mjs +119 -924
  35. package/lib/cli/project-scaffolder/prompt-builders.mjs +69 -84
  36. package/lib/cli/project-scaffolder.mjs +0 -2
  37. package/lib/cli/utils/filesystem.mjs +79 -0
  38. package/lib/cli/utils/managed-surface.mjs +237 -0
  39. package/lib/cli/utils/prompting.mjs +44 -0
  40. package/lib/cli/utils.mjs +33 -335
  41. package/package.json +21 -2
  42. package/scripts/bump-version.mjs +15 -13
  43. package/scripts/clean-local-artifacts.mjs +76 -0
  44. package/scripts/docs-quality-drift-report.mjs +5 -0
  45. package/scripts/frontend-usability-audit.mjs +23 -19
  46. package/scripts/governance-weekly-report.mjs +37 -15
  47. package/scripts/single-source-lazy-loading-audit.mjs +24 -0
  48. package/scripts/sync-thin-adapters.mjs +99 -129
  49. package/scripts/v3-purge-audit.mjs +5 -0
  50. package/scripts/validate/config.mjs +10 -0
  51. package/scripts/validate/coverage-checks.mjs +55 -0
  52. package/scripts/validate.mjs +20 -0
  53. package/.agent-context/marketplace/trust-tiers.json +0 -114
  54. package/.agent-context/state/benchmark-analysis.json +0 -431
  55. package/.agent-context/state/benchmark-evidence-bundle.json +0 -1040
  56. package/.agent-context/state/benchmark-history.json +0 -75
  57. package/.agent-context/state/benchmark-trend-report.csv +0 -5
  58. package/.agent-context/state/benchmark-trend-report.json +0 -140
  59. package/.agent-context/state/benchmark-writer-judge-matrix.json +0 -462
  60. package/.agent-context/state/memory-continuity-benchmark.json +0 -132
  61. package/.agent-context/state/onboarding-report.json +0 -102
  62. package/.agent-context/state/quality-trend-report.json +0 -89
  63. package/.agent-context/state/token-optimization-benchmark.json +0 -130
  64. package/.agent-context/state/weekly-governance-report.json +0 -329
  65. package/lib/cli/compatibility.mjs +0 -124
  66. package/scripts/validate-evidence-bundle.mjs +0 -76
package/AGENTS.md CHANGED
@@ -2,45 +2,42 @@
2
2
 
3
3
  Adapter Mode: thin
4
4
  Adapter Source: .instructions.md
5
- Canonical Snapshot SHA256: 06e3f81d1df0e86bad6c3fe2a4623da640a1ea88b3124aecf1c10214cdc178e6
5
+ Canonical Snapshot SHA256: 75652106d1fc453e9407eb9301e7f38de2e0159190dc47fb0b6e377859d91a46
6
6
 
7
- This file is an adapter entrypoint for agent discovery.
8
- The canonical policy source is [.instructions.md](.instructions.md).
9
-
10
- If your host stops at this file instead of following the full chain, obey the Critical Bootstrap Floor below before coding.
7
+ This repository is governed by a strict instruction contract.
8
+ Use [.instructions.md](.instructions.md) as the canonical policy source.
9
+ Use .agent-context/ for technical rules, prompts, checklists, policies, and state.
10
+ Treat README.md as overview/install/user context only when governance files conflict.
11
11
 
12
12
  ## Critical Bootstrap Floor
13
13
 
14
- - If `.agent-instructions.md` exists, prefer it immediately after this file because it is the compiled project-specific snapshot.
15
- - Memory continuity does not replace bootstrap loading. It is host-dependent project memory, not a guarantee that instructions were reloaded for this session.
16
- - For UI, UX, layout, screen, tailwind, frontend, or redesign requests: load [.agent-context/prompts/bootstrap-design.md](.agent-context/prompts/bootstrap-design.md) and [.agent-context/rules/frontend-architecture.md](.agent-context/rules/frontend-architecture.md) before editing code.
14
+ - If your host stops at this file, continue the chain manually before coding.
15
+ - Read `.agent-instructions.md` next when it exists.
16
+ - Memory continuity does not replace bootstrap loading.
17
+ - For UI, UX, layout, screen, tailwind, frontend, or redesign requests, load [bootstrap-design.md](.agent-context/prompts/bootstrap-design.md) and [frontend-architecture.md](.agent-context/rules/frontend-architecture.md) before code edits.
17
18
  - For UI scope, include a one-line Motion/Palette Decision in the Bootstrap Receipt; product categories are heuristics, not style presets.
18
- - For UI scope: if `docs/DESIGN.md` or `docs/design-intent.json` is missing, materialize or refine them before implementing UI changes.
19
- - For documentation-first requests: create or refine required project docs in English by default and do not write application, firmware, or UI code until the user asks or approves.
20
- - For backend, API, data, auth, error, event, queue, worker, or distributed-system requests: load the relevant global rules from [.agent-context/rules/](.agent-context/rules); do not create stack-specific governance adapters.
21
- - For refactor, improve, clean up, or fix requests: inspect the active rules and propose a plan before editing.
22
- - For new project or module requests: clarify constraints, runtime decisions, and required docs before generating code.
23
- - For ecosystem, framework, dependency, or Docker claims: perform live web research instead of relying on stale local heuristics.
19
+ - For UI scope, create or refine `docs/DESIGN.md` and `docs/design-intent.json` before UI implementation.
20
+ - For documentation-first requests, create or refine required project docs in English by default and do not write application, firmware, or UI code until the user asks or approves.
21
+ - For backend, API, data, auth, error, event, queue, worker, or distributed-system requests, load only relevant global rules from .agent-context/rules/ ([link](.agent-context/rules)).
22
+ - For ecosystem, framework, dependency, or Docker claims, perform live web research.
23
+ - Resolve runtime choices from project evidence and live official documentation; resolve structural planning from constraints and architecture boundaries.
24
24
 
25
25
  ## Mandatory Bootstrap Chain
26
26
 
27
- 1. Load [.instructions.md](.instructions.md) first as the canonical baseline.
28
- 2. If `.agent-instructions.md` exists, read it next as the compiled project-specific snapshot.
29
- 3. Read baseline governance from [.agent-context/rules/](.agent-context/rules).
30
- 4. Apply request templates from [.agent-context/prompts/](.agent-context/prompts).
31
- 5. Enforce review contracts from [.agent-context/review-checklists/](.agent-context/review-checklists).
32
- 6. Read change-risk maps and continuity state from [.agent-context/state/](.agent-context/state).
33
- 7. Enforce policy thresholds from [.agent-context/policies/](.agent-context/policies).
34
- 8. Use runtime evidence, structure, and live research signals from project context docs.
27
+ 1. Load [.instructions.md](.instructions.md).
28
+ 2. Load `.agent-instructions.md` when present.
29
+ 3. Load only relevant files from .agent-context/rules/ ([link](.agent-context/rules)).
30
+ 4. Apply matching prompts from .agent-context/prompts/ ([link](.agent-context/prompts)).
31
+ 5. Enforce .agent-context/review-checklists/ ([link](.agent-context/review-checklists/pr-checklist.md)).
32
+ 6. Use .agent-context/state/ ([link](.agent-context/state)) and .agent-context/policies/ ([link](.agent-context/policies)) only when relevant.
33
+ 7. Use project docs and live evidence for runtime, dependency, and architecture claims.
35
34
 
36
35
  ## Bootstrap Receipt
37
36
 
38
37
  For non-trivial coding, review, planning, or governance work, produce a short Bootstrap Receipt before implementation output: `loaded_files`, `selected_rules`, `skipped_rules`, `unreachable_files`, and `validation_plan`.
39
38
 
40
- ## Trigger Rules
39
+ ## Completion Gate
41
40
 
42
- - New project or module requests: propose scope, constraints, and required docs first, then wait for approval.
43
- - Refactor or fix requests: propose plan first, then execute safely.
44
- - Completion: run [.agent-context/review-checklists/pr-checklist.md](.agent-context/review-checklists/pr-checklist.md) before declaring done.
41
+ Run [pr-checklist.md](.agent-context/review-checklists/pr-checklist.md) before declaring work complete.
45
42
 
46
43
  If this adapter drifts from canonical behavior, refresh from [.instructions.md](.instructions.md) and update the hash metadata.
package/CLAUDE.md ADDED
@@ -0,0 +1,43 @@
1
+ # CLAUDE.md - Thin Adapter
2
+
3
+ Adapter Mode: thin
4
+ Adapter Source: .instructions.md
5
+ Canonical Snapshot SHA256: 75652106d1fc453e9407eb9301e7f38de2e0159190dc47fb0b6e377859d91a46
6
+
7
+ This repository is governed by a strict instruction contract.
8
+ Use [.instructions.md](.instructions.md) as the canonical policy source.
9
+ Use .agent-context/ for technical rules, prompts, checklists, policies, and state.
10
+ Treat README.md as overview/install/user context only when governance files conflict.
11
+
12
+ ## Critical Bootstrap Floor
13
+
14
+ - If your host stops at this file, continue the chain manually before coding.
15
+ - Read `.agent-instructions.md` next when it exists.
16
+ - Memory continuity does not replace bootstrap loading.
17
+ - For UI, UX, layout, screen, tailwind, frontend, or redesign requests, load [bootstrap-design.md](.agent-context/prompts/bootstrap-design.md) and [frontend-architecture.md](.agent-context/rules/frontend-architecture.md) before code edits.
18
+ - For UI scope, include a one-line Motion/Palette Decision in the Bootstrap Receipt; product categories are heuristics, not style presets.
19
+ - For UI scope, create or refine `docs/DESIGN.md` and `docs/design-intent.json` before UI implementation.
20
+ - For documentation-first requests, create or refine required project docs in English by default and do not write application, firmware, or UI code until the user asks or approves.
21
+ - For backend, API, data, auth, error, event, queue, worker, or distributed-system requests, load only relevant global rules from .agent-context/rules/ ([link](.agent-context/rules)).
22
+ - For ecosystem, framework, dependency, or Docker claims, perform live web research.
23
+ - Resolve runtime choices from project evidence and live official documentation; resolve structural planning from constraints and architecture boundaries.
24
+
25
+ ## Mandatory Bootstrap Chain
26
+
27
+ 1. Load [.instructions.md](.instructions.md).
28
+ 2. Load `.agent-instructions.md` when present.
29
+ 3. Load only relevant files from .agent-context/rules/ ([link](.agent-context/rules)).
30
+ 4. Apply matching prompts from .agent-context/prompts/ ([link](.agent-context/prompts)).
31
+ 5. Enforce .agent-context/review-checklists/ ([link](.agent-context/review-checklists/pr-checklist.md)).
32
+ 6. Use .agent-context/state/ ([link](.agent-context/state)) and .agent-context/policies/ ([link](.agent-context/policies)) only when relevant.
33
+ 7. Use project docs and live evidence for runtime, dependency, and architecture claims.
34
+
35
+ ## Bootstrap Receipt
36
+
37
+ For non-trivial coding, review, planning, or governance work, produce a short Bootstrap Receipt before implementation output: `loaded_files`, `selected_rules`, `skipped_rules`, `unreachable_files`, and `validation_plan`.
38
+
39
+ ## Completion Gate
40
+
41
+ Run [pr-checklist.md](.agent-context/review-checklists/pr-checklist.md) before declaring work complete.
42
+
43
+ If this adapter drifts from canonical behavior, refresh from [.instructions.md](.instructions.md) and update the hash metadata.
package/CONTRIBUTING.md CHANGED
@@ -63,7 +63,7 @@ If all three are "yes", it belongs here.
63
63
  - Core principle (1-2 sentences)
64
64
  - BANNED / REQUIRED sections with enforceable boundaries
65
65
  - Decision tree or quick ruleset when it reduces ambiguity
66
- 3. Update `AGENTS.md` rules manifest table
66
+ 3. Update `.instructions.md` or `.agent-context/` as the source, then regenerate thin adapters with `npm run sync:adapters`
67
67
  4. Update `review-checklists/pr-checklist.md` when the rule is part of review scope
68
68
  5. Validate and PR
69
69
 
@@ -89,12 +89,14 @@ If all three are "yes", it belongs here.
89
89
  - Rules without concrete enforcement boundaries
90
90
  - Stack profiles for languages the author doesn't actually use in production
91
91
  - Blueprints that are just folder structures without code patterns
92
- - PRs that don't update the relevant manifest files (AGENTS.md, checklists)
92
+ - PRs that don't update the relevant source files, generated adapters, and checklists
93
93
 
94
94
  ---
95
95
 
96
96
  ## Local Development
97
97
 
98
+ The npm package is published under `@ryuenn3123`, while the GitHub repository is hosted under `fatidaprilian`.
99
+
98
100
  ```bash
99
101
  # Clone
100
102
  git clone https://github.com/fatidaprilian/Agentic-Senior-Core.git
@@ -103,6 +105,9 @@ cd Agentic-Senior-Core
103
105
  # Validate
104
106
  npm run validate
105
107
 
108
+ # Clean ignored local reports/backups when the workspace gets noisy
109
+ npm run clean:local
110
+
106
111
  # Test interactive CLI
107
112
  node ./bin/agentic-senior-core.js init /tmp/test-project
108
113
  ```
package/GEMINI.md ADDED
@@ -0,0 +1,43 @@
1
+ # GEMINI.md - Thin Adapter
2
+
3
+ Adapter Mode: thin
4
+ Adapter Source: .instructions.md
5
+ Canonical Snapshot SHA256: 75652106d1fc453e9407eb9301e7f38de2e0159190dc47fb0b6e377859d91a46
6
+
7
+ This repository is governed by a strict instruction contract.
8
+ Use [.instructions.md](.instructions.md) as the canonical policy source.
9
+ Use .agent-context/ for technical rules, prompts, checklists, policies, and state.
10
+ Treat README.md as overview/install/user context only when governance files conflict.
11
+
12
+ ## Critical Bootstrap Floor
13
+
14
+ - If your host stops at this file, continue the chain manually before coding.
15
+ - Read `.agent-instructions.md` next when it exists.
16
+ - Memory continuity does not replace bootstrap loading.
17
+ - For UI, UX, layout, screen, tailwind, frontend, or redesign requests, load [bootstrap-design.md](.agent-context/prompts/bootstrap-design.md) and [frontend-architecture.md](.agent-context/rules/frontend-architecture.md) before code edits.
18
+ - For UI scope, include a one-line Motion/Palette Decision in the Bootstrap Receipt; product categories are heuristics, not style presets.
19
+ - For UI scope, create or refine `docs/DESIGN.md` and `docs/design-intent.json` before UI implementation.
20
+ - For documentation-first requests, create or refine required project docs in English by default and do not write application, firmware, or UI code until the user asks or approves.
21
+ - For backend, API, data, auth, error, event, queue, worker, or distributed-system requests, load only relevant global rules from .agent-context/rules/ ([link](.agent-context/rules)).
22
+ - For ecosystem, framework, dependency, or Docker claims, perform live web research.
23
+ - Resolve runtime choices from project evidence and live official documentation; resolve structural planning from constraints and architecture boundaries.
24
+
25
+ ## Mandatory Bootstrap Chain
26
+
27
+ 1. Load [.instructions.md](.instructions.md).
28
+ 2. Load `.agent-instructions.md` when present.
29
+ 3. Load only relevant files from .agent-context/rules/ ([link](.agent-context/rules)).
30
+ 4. Apply matching prompts from .agent-context/prompts/ ([link](.agent-context/prompts)).
31
+ 5. Enforce .agent-context/review-checklists/ ([link](.agent-context/review-checklists/pr-checklist.md)).
32
+ 6. Use .agent-context/state/ ([link](.agent-context/state)) and .agent-context/policies/ ([link](.agent-context/policies)) only when relevant.
33
+ 7. Use project docs and live evidence for runtime, dependency, and architecture claims.
34
+
35
+ ## Bootstrap Receipt
36
+
37
+ For non-trivial coding, review, planning, or governance work, produce a short Bootstrap Receipt before implementation output: `loaded_files`, `selected_rules`, `skipped_rules`, `unreachable_files`, and `validation_plan`.
38
+
39
+ ## Completion Gate
40
+
41
+ Run [pr-checklist.md](.agent-context/review-checklists/pr-checklist.md) before declaring work complete.
42
+
43
+ If this adapter drifts from canonical behavior, refresh from [.instructions.md](.instructions.md) and update the hash metadata.
package/README.md CHANGED
@@ -10,12 +10,12 @@
10
10
  **Production-grade Rules Engine (Governance Engine) for AI coding agents.**
11
11
  Works with Cursor, Windsurf, GitHub Copilot, Claude Code, Gemini, and other LLM-powered IDE workflows.
12
12
 
13
- Latest release: 3.0.30 (2026-04-25).
13
+ Latest release: 3.0.39 (2026-04-30).
14
14
 
15
- Highlights in 3.0.30:
16
- - Root `mcp.json` now reflects the current 9-layer governance model instead of the old 8-layer metadata.
17
- - MCP knowledge metadata now includes 15 rules, 4 prompts including `bootstrap-design`, and the project-context layer.
18
- - MCP workflow wording now reinforces scope-first relevant-layer injection instead of eager load-all context.
15
+ Highlights in 3.0.39:
16
+ - Post-release hygiene removes stale V2 evidence-bundle and Bun lockfile drift surfaces.
17
+ - Package and lockfile validation now blocks version drift and accidental dual package-manager state.
18
+ - Repo-local agent context now documents frontend/backend governance boundaries and anti-grid wallpaper handling.
19
19
 
20
20
  </div>
21
21
 
@@ -29,11 +29,12 @@ Highlights in 3.0.30:
29
29
  npx @ryuenn3123/agentic-senior-core init
30
30
  ```
31
31
 
32
- One command to initialize rules, checklists, and strict AI coding guidelines context for your project.
32
+ One command to initialize rules, checklists, thin discovery adapters, and a compiled AI rulebook for your project.
33
33
 
34
34
  > **See [docs/deep-dive.md](docs/deep-dive.md) and [docs/roadmap.md](docs/roadmap.md) for advanced configuration, planning mode, snapshot, and realtime options.**
35
35
 
36
36
  - This command writes `.agent-context/state/v3-purge-audit.json` and reports whether static directory deletion is safe.
37
+ - Package scope is `@ryuenn3123`; the GitHub repository owner is `fatidaprilian`.
37
38
 
38
39
  ---
39
40
 
@@ -73,10 +74,11 @@ If you see `Property $schema is not allowed`, keep `.vscode/mcp.json` without `$
73
74
 
74
75
  | Command | Purpose |
75
76
  |---------|---------|
76
- | `agentic-senior-core init` | Initialize the project guidance pack and compiled AI rulebook |
77
+ | `agentic-senior-core init` | Initialize the project guidance pack, thin adapters, and compiled AI rulebook |
77
78
  | `agentic-senior-core upgrade --dry-run` | Preview safe upgrades |
78
79
  | `agentic-senior-core optimize --show` | Show token optimization state |
79
80
  | `npm run audit:v3-purge` | Run deep purge readiness audit (no deletion) |
81
+ | `npm run clean:local` | Remove ignored local reports, backups, benchmarks, and active-memory state |
80
82
  | `agentic-senior-core mcp` | Start local MCP stdio runtime |
81
83
 
82
84
  ---
@@ -93,6 +95,22 @@ Use `--dry-run` first to preview changes safely, then apply with `--yes`.
93
95
  Upgrade now performs managed-surface synchronization by default: obsolete governance files under managed paths are pruned so the pack stays aligned with the latest release.
94
96
  Use `--no-prune` if you want to keep legacy managed files.
95
97
 
98
+ ## Instruction Entrypoints
99
+
100
+ The canonical source is `.instructions.md`.
101
+
102
+ Generated bridge files stay small:
103
+ - `AGENTS.md`
104
+ - `CLAUDE.md`
105
+ - `GEMINI.md`
106
+ - `.cursor/rules/agentic-senior-core.mdc`
107
+ - `.windsurf/rules/agentic-senior-core.md`
108
+ - `.github/copilot-instructions.md`
109
+ - `.github/instructions/agentic-senior-core.instructions.md`
110
+ - `.gemini/instructions.md`
111
+
112
+ Legacy root files `.cursorrules`, `.windsurfrules`, and `.clauderc` are thin compatibility adapters. They point to `.agent-instructions.md` when the compiled rulebook exists, with `.instructions.md` as the fallback source.
113
+
96
114
  ---
97
115
 
98
116
  ## Terminology Mapping (Final)
@@ -2,6 +2,7 @@ import fs from 'node:fs/promises';
2
2
  import path from 'node:path';
3
3
  import crypto from 'node:crypto';
4
4
  import { pathExists, ensureDirectory } from './utils.mjs';
5
+ import { entryPointFiles } from './constants.mjs';
5
6
 
6
7
  const BACKUP_DIR_NAME = '.agentic-backup';
7
8
 
@@ -44,7 +45,7 @@ async function getFilesInDirectory(dirPath) {
44
45
 
45
46
  /**
46
47
  * Creates a backup of specific paths in the target directory.
47
- * Currently backs up: .cursorrules, .windsurfrules, and the entire .agent-context directory.
48
+ * Currently backs up: managed entrypoint files and the entire .agent-context directory.
48
49
  * @param {string} targetDirectoryPath
49
50
  */
50
51
  export async function createBackup(targetDirectoryPath) {
@@ -55,9 +56,8 @@ export async function createBackup(targetDirectoryPath) {
55
56
  await ensureDirectory(objectsDir);
56
57
 
57
58
  const pathsToTrack = [
58
- path.join(targetDirectoryPath, '.cursorrules'),
59
- path.join(targetDirectoryPath, '.windsurfrules'),
60
- path.join(targetDirectoryPath, '.agent-context')
59
+ ...entryPointFiles.map((entryPointFileName) => path.join(targetDirectoryPath, entryPointFileName)),
60
+ path.join(targetDirectoryPath, '.agent-context'),
61
61
  ];
62
62
 
63
63
  const resolvedFilesToTrack = [];
@@ -0,0 +1,101 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+
4
+ import { buildDesignIntentSeedFromSignals } from '../../project-scaffolder.mjs';
5
+
6
+ function normalizeContextLine(rawText) {
7
+ return String(rawText || '')
8
+ .replace(/\s+/g, ' ')
9
+ .trim();
10
+ }
11
+
12
+ async function readTextIfExists(filePath) {
13
+ try {
14
+ return await fs.readFile(filePath, 'utf8');
15
+ } catch {
16
+ return '';
17
+ }
18
+ }
19
+
20
+ function extractMarkdownContext(rawMarkdown) {
21
+ return String(rawMarkdown || '')
22
+ .split(/\r?\n/)
23
+ .map((line) => normalizeContextLine(line.replace(/^#+\s*/, '')))
24
+ .filter((line) => line && !line.startsWith('---') && !line.startsWith('```'))
25
+ .slice(0, 3)
26
+ .join(' ');
27
+ }
28
+
29
+ export async function inferExistingProjectDescriptionHint(targetDirectoryPath) {
30
+ const evidence = [];
31
+ const packageJsonContent = await readTextIfExists(path.join(targetDirectoryPath, 'package.json'));
32
+
33
+ if (packageJsonContent) {
34
+ try {
35
+ const packageManifest = JSON.parse(packageJsonContent);
36
+ const packageSummary = [
37
+ normalizeContextLine(packageManifest.name),
38
+ normalizeContextLine(packageManifest.description),
39
+ ].filter(Boolean).join(': ');
40
+
41
+ if (packageSummary) {
42
+ evidence.push(`package.json: ${packageSummary}`);
43
+ }
44
+ } catch {
45
+ // Invalid package metadata should not block init; other files can still provide context.
46
+ }
47
+ }
48
+
49
+ for (const relativeDocPath of ['docs/project-brief.md', 'docs/README.md', 'README.md']) {
50
+ const docContext = extractMarkdownContext(
51
+ await readTextIfExists(path.join(targetDirectoryPath, relativeDocPath))
52
+ );
53
+
54
+ if (docContext) {
55
+ evidence.push(`${relativeDocPath}: ${docContext}`);
56
+ }
57
+ }
58
+
59
+ return evidence.slice(0, 3).join(' | ');
60
+ }
61
+
62
+ export function buildInitExistingProjectDesignIntentSeed({
63
+ targetDirectoryPath,
64
+ packageManifest,
65
+ selectedStackFileName,
66
+ selectedBlueprintFileName,
67
+ uiScopeSignals,
68
+ projectDescriptionHint,
69
+ }) {
70
+ const projectName = String(packageManifest?.name || path.basename(targetDirectoryPath)).trim() || 'existing-ui-project';
71
+ const isMobileUiProject = String(selectedStackFileName || '').toLowerCase().includes('react-native')
72
+ || String(selectedStackFileName || '').toLowerCase().includes('flutter')
73
+ || uiScopeSignals.signalReasons.some((signalReason) => signalReason.includes('android') || signalReason.includes('ios'));
74
+ const resolvedDomain = isMobileUiProject ? 'Mobile app' : 'Web application';
75
+ const projectDescription = String(packageManifest?.description || projectDescriptionHint || '').trim()
76
+ || `Existing ${resolvedDomain.toLowerCase()} detected during init. Create a project-specific dynamic design contract before shipping new UI work.`;
77
+
78
+ return buildDesignIntentSeedFromSignals({
79
+ projectName,
80
+ projectDescription,
81
+ primaryDomain: resolvedDomain,
82
+ features: [],
83
+ initContext: {
84
+ stackFileName: selectedStackFileName,
85
+ blueprintFileName: selectedBlueprintFileName,
86
+ },
87
+ status: 'seed-generated-during-init',
88
+ supplementalFields: {
89
+ initSignals: {
90
+ detectedFrom: uiScopeSignals.signalReasons,
91
+ generatedBy: 'init-existing-project-seed',
92
+ },
93
+ repoEvidence: {
94
+ uiSignalReasons: uiScopeSignals.signalReasons,
95
+ frontendMetrics: uiScopeSignals.frontendEvidenceMetrics || null,
96
+ designEvidenceSummary: uiScopeSignals.designEvidenceSummary || null,
97
+ workspaceUiEntries: uiScopeSignals.workspaceUiEntries || [],
98
+ },
99
+ },
100
+ });
101
+ }
@@ -0,0 +1,59 @@
1
+ import { RUNTIME_ENVIRONMENT_CHOICES } from '../../constants.mjs';
2
+
3
+ export function resolveRuntimeEnvironmentKeyFromLabel(selectedRuntimeEnvironmentLabel) {
4
+ const runtimeEnvironmentEntry = RUNTIME_ENVIRONMENT_CHOICES.find(
5
+ (runtimeEnvironmentChoice) => runtimeEnvironmentChoice.label === selectedRuntimeEnvironmentLabel
6
+ );
7
+
8
+ return runtimeEnvironmentEntry?.key || null;
9
+ }
10
+
11
+ export function resolveRuntimeEnvironmentLabelFromKey(runtimeEnvironmentKey) {
12
+ const runtimeEnvironmentEntry = RUNTIME_ENVIRONMENT_CHOICES.find(
13
+ (runtimeEnvironmentChoice) => runtimeEnvironmentChoice.key === runtimeEnvironmentKey
14
+ );
15
+
16
+ return runtimeEnvironmentEntry?.label || runtimeEnvironmentKey;
17
+ }
18
+
19
+ export function detectRuntimeEnvironment() {
20
+ const isWslEnvironment = Boolean(process.env.WSL_DISTRO_NAME || process.env.WSL_INTEROP || process.env.__IS_WSL_TEST__);
21
+
22
+ if (isWslEnvironment) {
23
+ return {
24
+ key: 'linux-wsl',
25
+ label: resolveRuntimeEnvironmentLabelFromKey('linux-wsl'),
26
+ shellFamily: 'bash',
27
+ isAutoDetected: true,
28
+ source: 'WSL environment markers',
29
+ };
30
+ }
31
+
32
+ if (process.platform === 'win32') {
33
+ return {
34
+ key: 'windows',
35
+ label: resolveRuntimeEnvironmentLabelFromKey('windows'),
36
+ shellFamily: 'powershell',
37
+ isAutoDetected: true,
38
+ source: 'process.platform',
39
+ };
40
+ }
41
+
42
+ if (process.platform === 'darwin') {
43
+ return {
44
+ key: 'macos',
45
+ label: resolveRuntimeEnvironmentLabelFromKey('macos'),
46
+ shellFamily: 'bash',
47
+ isAutoDetected: true,
48
+ source: 'process.platform',
49
+ };
50
+ }
51
+
52
+ return {
53
+ key: 'linux',
54
+ label: resolveRuntimeEnvironmentLabelFromKey('linux'),
55
+ shellFamily: 'bash',
56
+ isAutoDetected: true,
57
+ source: 'process.platform',
58
+ };
59
+ }
@@ -0,0 +1,83 @@
1
+ import { PROJECT_SCOPE_CHOICES } from '../../constants.mjs';
2
+ import { matchFileNameFromInput, normalizeChoiceInput } from '../../utils.mjs';
3
+
4
+ export function resolveProjectScopeLabelFromKey(projectScopeKey) {
5
+ return PROJECT_SCOPE_CHOICES.find((scopeChoice) => scopeChoice.key === projectScopeKey)?.label
6
+ || PROJECT_SCOPE_CHOICES.find((scopeChoice) => scopeChoice.key === 'both')?.label
7
+ || 'Both (frontend + backend)';
8
+ }
9
+
10
+ export function inferProjectScopeFromDiscoveryAnswers(discoveryAnswers) {
11
+ const normalizedDomain = String(discoveryAnswers?.primaryDomain || '').trim().toLowerCase();
12
+ const normalizedDescription = [
13
+ discoveryAnswers?.projectDescription,
14
+ ...(Array.isArray(discoveryAnswers?.features) ? discoveryAnswers.features : []),
15
+ ].join(' ').toLowerCase();
16
+
17
+ if (
18
+ normalizedDomain.includes('api service')
19
+ || normalizedDomain.includes('cli tool')
20
+ || normalizedDomain.includes('library')
21
+ ) {
22
+ return 'backend-only';
23
+ }
24
+
25
+ if (normalizedDomain.includes('mobile app')) {
26
+ return 'frontend-only';
27
+ }
28
+
29
+ if (normalizedDomain.includes('web application')) {
30
+ if (/(landing page|marketing site|showcase|portfolio|brochure|company profile)/.test(normalizedDescription)) {
31
+ return 'frontend-only';
32
+ }
33
+
34
+ return 'both';
35
+ }
36
+
37
+ return 'both';
38
+ }
39
+
40
+ export function resolveSilentCiGuardrailsDefault({
41
+ initOptions,
42
+ selectedPreset,
43
+ selectedPolicyProfile,
44
+ }) {
45
+ if (typeof initOptions.ci === 'boolean') {
46
+ return {
47
+ value: initOptions.ci,
48
+ shouldAsk: false,
49
+ };
50
+ }
51
+
52
+ if (typeof selectedPreset?.ci === 'boolean') {
53
+ return {
54
+ value: selectedPreset.ci,
55
+ shouldAsk: false,
56
+ };
57
+ }
58
+
59
+ if (selectedPolicyProfile.lockCi) {
60
+ return {
61
+ value: selectedPolicyProfile.defaultCi,
62
+ shouldAsk: false,
63
+ };
64
+ }
65
+
66
+ return {
67
+ value: selectedPolicyProfile.defaultCi,
68
+ shouldAsk: true,
69
+ };
70
+ }
71
+
72
+ export function normalizeExplicitProfileFileName(rawInput, discoveredFileNames) {
73
+ const matchedFileName = Array.isArray(discoveredFileNames) && discoveredFileNames.length > 0
74
+ ? matchFileNameFromInput(rawInput, discoveredFileNames)
75
+ : null;
76
+
77
+ if (matchedFileName) {
78
+ return matchedFileName;
79
+ }
80
+
81
+ const normalizedBaseName = normalizeChoiceInput(String(rawInput || '').replace(/\.md$/i, ''));
82
+ return normalizedBaseName ? `${normalizedBaseName}.md` : null;
83
+ }