@mainahq/core 1.0.2 → 1.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.
- package/package.json +1 -1
- package/src/ai/__tests__/availability.test.ts +131 -0
- package/src/ai/__tests__/delegation.test.ts +55 -1
- package/src/ai/availability.ts +23 -0
- package/src/ai/delegation.ts +5 -3
- package/src/context/__tests__/budget.test.ts +29 -6
- package/src/context/__tests__/engine.test.ts +1 -0
- package/src/context/__tests__/selector.test.ts +23 -3
- package/src/context/__tests__/wiki.test.ts +349 -0
- package/src/context/budget.ts +12 -8
- package/src/context/engine.ts +37 -0
- package/src/context/selector.ts +30 -4
- package/src/context/wiki.ts +296 -0
- package/src/db/index.ts +12 -0
- package/src/feedback/__tests__/capture.test.ts +166 -0
- package/src/feedback/__tests__/signals.test.ts +144 -0
- package/src/feedback/__tests__/tmp-capture-1775575256633-lah0etnzlj/feedback.db +0 -0
- package/src/feedback/__tests__/tmp-capture-1775575256640-2xmjme4qraa/feedback.db +0 -0
- package/src/feedback/capture.ts +102 -0
- package/src/feedback/signals.ts +68 -0
- package/src/index.ts +108 -1
- package/src/init/__tests__/init.test.ts +477 -18
- package/src/init/index.ts +419 -13
- package/src/language/__tests__/__fixtures__/detect/composer.lock +1 -0
- package/src/prompts/defaults/index.ts +3 -1
- package/src/prompts/defaults/wiki-compile.md +20 -0
- package/src/prompts/defaults/wiki-query.md +18 -0
- package/src/stats/__tests__/tool-usage.test.ts +133 -0
- package/src/stats/tracker.ts +92 -0
- package/src/verify/__tests__/builtin.test.ts +270 -0
- package/src/verify/__tests__/pipeline.test.ts +11 -8
- package/src/verify/builtin.ts +350 -0
- package/src/verify/pipeline.ts +32 -2
- package/src/verify/tools/__tests__/wiki-lint.test.ts +784 -0
- package/src/verify/tools/wiki-lint-runner.ts +38 -0
- package/src/verify/tools/wiki-lint.ts +898 -0
- package/src/wiki/__tests__/compiler.test.ts +389 -0
- package/src/wiki/__tests__/extractors/code.test.ts +99 -0
- package/src/wiki/__tests__/extractors/decision.test.ts +323 -0
- package/src/wiki/__tests__/extractors/feature.test.ts +186 -0
- package/src/wiki/__tests__/extractors/workflow.test.ts +131 -0
- package/src/wiki/__tests__/graph.test.ts +344 -0
- package/src/wiki/__tests__/hooks.test.ts +119 -0
- package/src/wiki/__tests__/indexer.test.ts +285 -0
- package/src/wiki/__tests__/linker.test.ts +230 -0
- package/src/wiki/__tests__/louvain.test.ts +229 -0
- package/src/wiki/__tests__/query.test.ts +316 -0
- package/src/wiki/__tests__/schema.test.ts +114 -0
- package/src/wiki/__tests__/signals.test.ts +474 -0
- package/src/wiki/__tests__/state.test.ts +168 -0
- package/src/wiki/__tests__/tracking.test.ts +118 -0
- package/src/wiki/__tests__/types.test.ts +387 -0
- package/src/wiki/compiler.ts +1075 -0
- package/src/wiki/extractors/code.ts +90 -0
- package/src/wiki/extractors/decision.ts +217 -0
- package/src/wiki/extractors/feature.ts +206 -0
- package/src/wiki/extractors/workflow.ts +112 -0
- package/src/wiki/graph.ts +445 -0
- package/src/wiki/hooks.ts +49 -0
- package/src/wiki/indexer.ts +105 -0
- package/src/wiki/linker.ts +117 -0
- package/src/wiki/louvain.ts +190 -0
- package/src/wiki/prompts/compile-architecture.md +59 -0
- package/src/wiki/prompts/compile-decision.md +66 -0
- package/src/wiki/prompts/compile-entity.md +56 -0
- package/src/wiki/prompts/compile-feature.md +60 -0
- package/src/wiki/prompts/compile-module.md +42 -0
- package/src/wiki/prompts/wiki-query.md +25 -0
- package/src/wiki/query.ts +338 -0
- package/src/wiki/schema.ts +111 -0
- package/src/wiki/signals.ts +368 -0
- package/src/wiki/state.ts +89 -0
- package/src/wiki/tracking.ts +30 -0
- package/src/wiki/types.ts +169 -0
- package/src/workflow/context.ts +26 -0
package/src/init/index.ts
CHANGED
|
@@ -28,6 +28,7 @@ export interface InitOptions {
|
|
|
28
28
|
export interface InitReport {
|
|
29
29
|
created: string[];
|
|
30
30
|
skipped: string[];
|
|
31
|
+
updated: string[];
|
|
31
32
|
directory: string;
|
|
32
33
|
detectedStack: DetectedStack;
|
|
33
34
|
detectedTools: DetectedTool[];
|
|
@@ -331,7 +332,9 @@ const MCP_TOOLS_TABLE = `| Tool | When to use |
|
|
|
331
332
|
| \`suggestTests\` | When implementing — generate TDD test stubs |
|
|
332
333
|
| \`getConventions\` | Understand project coding conventions |
|
|
333
334
|
| \`explainModule\` | Understand a module's purpose and dependencies |
|
|
334
|
-
| \`analyzeFeature\` | Analyze a feature directory for consistency
|
|
335
|
+
| \`analyzeFeature\` | Analyze a feature directory for consistency |
|
|
336
|
+
| \`wikiQuery\` | Search wiki for codebase knowledge — "how does auth work?" |
|
|
337
|
+
| \`wikiStatus\` | Wiki health check — article counts, staleness, coverage |`;
|
|
335
338
|
|
|
336
339
|
// ── Templates ────────────────────────────────────────────────────────────────
|
|
337
340
|
|
|
@@ -464,6 +467,13 @@ maina commit # verify + commit
|
|
|
464
467
|
|
|
465
468
|
${MCP_TOOLS_TABLE}
|
|
466
469
|
|
|
470
|
+
## Wiki
|
|
471
|
+
|
|
472
|
+
If \`.maina/wiki/\` exists, use wiki tools for context:
|
|
473
|
+
- \`wikiQuery\` before coding — understand existing patterns and decisions
|
|
474
|
+
- \`wikiStatus\` to check health
|
|
475
|
+
- Wiki articles are loaded automatically as Context Engine Layer 5
|
|
476
|
+
|
|
467
477
|
## Config Files
|
|
468
478
|
| File | Purpose | Who Edits |
|
|
469
479
|
|------|---------|-----------|
|
|
@@ -473,6 +483,13 @@ ${MCP_TOOLS_TABLE}
|
|
|
473
483
|
| \`CLAUDE.md\` | Claude Code specific instructions | Optional, Claude Code users |
|
|
474
484
|
| \`GEMINI.md\` | Gemini CLI specific instructions | Optional, Gemini CLI users |
|
|
475
485
|
| \`.cursorrules\` | Cursor specific instructions | Optional, Cursor users |
|
|
486
|
+
| \`.windsurfrules\` | Windsurf specific instructions | Optional, Windsurf users |
|
|
487
|
+
| \`.clinerules\` | Cline specific instructions | Optional, Cline users |
|
|
488
|
+
| \`.continue/\` | Continue.dev config + MCP | Optional, Continue.dev users |
|
|
489
|
+
| \`.roo/\` | Roo Code MCP config + rules | Optional, Roo Code users |
|
|
490
|
+
| \`.amazonq/mcp.json\` | Amazon Q MCP config | Optional, Amazon Q users |
|
|
491
|
+
| \`.aider.conf.yml\` | Aider config | Optional, Aider users |
|
|
492
|
+
| \`CONVENTIONS.md\` | Project conventions (Aider, generic) | Team |
|
|
476
493
|
| \`.mcp.json\` | MCP server configuration | Team |
|
|
477
494
|
| \`.maina/prompts/*.md\` | Prompt overrides for review/commit/etc | Maina (via \`maina learn\`) |
|
|
478
495
|
|
|
@@ -505,6 +522,13 @@ Follow this order for every feature:
|
|
|
505
522
|
|
|
506
523
|
${MCP_TOOLS_TABLE}
|
|
507
524
|
|
|
525
|
+
## Wiki
|
|
526
|
+
|
|
527
|
+
If \`.maina/wiki/\` exists, use wiki tools for context:
|
|
528
|
+
- \`wikiQuery\` before coding — understand existing patterns and decisions
|
|
529
|
+
- \`wikiStatus\` to check health
|
|
530
|
+
- Wiki articles are loaded automatically as Context Engine Layer 5
|
|
531
|
+
|
|
508
532
|
## Conventions
|
|
509
533
|
|
|
510
534
|
- Runtime: ${stack.runtime}
|
|
@@ -519,15 +543,67 @@ Issues labeled \`audit\` come from maina's daily verification. Fix the specific
|
|
|
519
543
|
`;
|
|
520
544
|
}
|
|
521
545
|
|
|
546
|
+
// ── Maina Section (for merging into existing agent files) ──────────────────
|
|
547
|
+
|
|
548
|
+
/** Agent file names that support maina section merging */
|
|
549
|
+
const MERGEABLE_AGENT_FILES = [
|
|
550
|
+
"AGENTS.md",
|
|
551
|
+
"CLAUDE.md",
|
|
552
|
+
"GEMINI.md",
|
|
553
|
+
".cursorrules",
|
|
554
|
+
".github/copilot-instructions.md",
|
|
555
|
+
".windsurfrules",
|
|
556
|
+
".clinerules",
|
|
557
|
+
".roo/rules/maina.md",
|
|
558
|
+
"CONVENTIONS.md",
|
|
559
|
+
];
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Build a standalone "## Maina" section that can be appended to an existing
|
|
563
|
+
* agent file. Contains essential maina workflow + MCP tools info.
|
|
564
|
+
*/
|
|
565
|
+
export function buildMainaSection(_stack: DetectedStack): string {
|
|
566
|
+
return `## Maina
|
|
567
|
+
|
|
568
|
+
This repo uses [Maina](https://mainahq.com) for verification-first development.
|
|
569
|
+
Read \`.maina/constitution.md\` for project DNA.
|
|
570
|
+
|
|
571
|
+
### Workflow
|
|
572
|
+
\`${WORKFLOW_ORDER}\`
|
|
573
|
+
|
|
574
|
+
### MCP Tools
|
|
575
|
+
${MCP_TOOLS_TABLE}
|
|
576
|
+
`;
|
|
577
|
+
}
|
|
578
|
+
|
|
522
579
|
// ── .mcp.json ───────────────────────────────────────────────────────────────
|
|
523
580
|
|
|
524
|
-
function buildMcpJson(): string {
|
|
581
|
+
function buildMcpJson(stack: DetectedStack): string {
|
|
582
|
+
const command = stack.runtime === "bun" ? "bunx" : "npx";
|
|
525
583
|
return JSON.stringify(
|
|
526
584
|
{
|
|
527
585
|
mcpServers: {
|
|
528
586
|
maina: {
|
|
529
|
-
command
|
|
530
|
-
args: ["--mcp"],
|
|
587
|
+
command,
|
|
588
|
+
args: ["@mainahq/cli", "--mcp"],
|
|
589
|
+
},
|
|
590
|
+
},
|
|
591
|
+
},
|
|
592
|
+
null,
|
|
593
|
+
2,
|
|
594
|
+
);
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
// ── .claude/settings.json (Claude Code MCP config) ─────────────────────────
|
|
598
|
+
|
|
599
|
+
function buildClaudeSettings(stack: DetectedStack): string {
|
|
600
|
+
const command = stack.runtime === "bun" ? "bunx" : "npx";
|
|
601
|
+
return JSON.stringify(
|
|
602
|
+
{
|
|
603
|
+
mcpServers: {
|
|
604
|
+
maina: {
|
|
605
|
+
command,
|
|
606
|
+
args: ["@mainahq/cli", "--mcp"],
|
|
531
607
|
},
|
|
532
608
|
},
|
|
533
609
|
},
|
|
@@ -556,16 +632,42 @@ Maina exposes MCP tools — use them in every session:
|
|
|
556
632
|
|
|
557
633
|
${MCP_TOOLS_TABLE}
|
|
558
634
|
|
|
635
|
+
## Wiki
|
|
636
|
+
|
|
637
|
+
If \`.maina/wiki/\` exists, use wiki tools for context:
|
|
638
|
+
- \`wikiQuery\` before coding — understand existing patterns and decisions
|
|
639
|
+
- \`wikiStatus\` to check health
|
|
640
|
+
- Wiki articles are loaded automatically as Context Engine Layer 5
|
|
641
|
+
|
|
559
642
|
## Commands
|
|
560
643
|
|
|
561
644
|
\`\`\`bash
|
|
562
|
-
|
|
563
|
-
maina
|
|
564
|
-
maina
|
|
565
|
-
maina
|
|
566
|
-
maina
|
|
567
|
-
maina
|
|
568
|
-
|
|
645
|
+
# Workflow
|
|
646
|
+
maina brainstorm # explore ideas interactively
|
|
647
|
+
maina ticket # create GitHub issue with module tagging
|
|
648
|
+
maina plan <name> # scaffold feature branch + directory
|
|
649
|
+
maina design # create ADR (architecture decision record)
|
|
650
|
+
maina spec # generate TDD test stubs from plan
|
|
651
|
+
|
|
652
|
+
# Verify & Review
|
|
653
|
+
maina verify # run full verification pipeline (12+ tools)
|
|
654
|
+
maina review # two-stage code review
|
|
655
|
+
maina slop # detect AI-generated slop patterns
|
|
656
|
+
maina commit # verify + commit staged changes
|
|
657
|
+
|
|
658
|
+
# Wiki (codebase knowledge)
|
|
659
|
+
maina wiki init # compile codebase knowledge wiki
|
|
660
|
+
maina wiki query # ask questions about the codebase
|
|
661
|
+
maina wiki compile # recompile wiki (incremental)
|
|
662
|
+
maina wiki status # wiki health dashboard
|
|
663
|
+
maina wiki lint # check wiki for issues
|
|
664
|
+
|
|
665
|
+
# Context & Info
|
|
666
|
+
maina context # generate focused codebase context
|
|
667
|
+
maina explain # explain a module with wiki context
|
|
668
|
+
maina doctor # check tool health
|
|
669
|
+
maina stats # verification metrics
|
|
670
|
+
maina status # branch health overview
|
|
569
671
|
\`\`\`
|
|
570
672
|
|
|
571
673
|
## Conventions
|
|
@@ -599,6 +701,13 @@ Maina exposes MCP tools via \`.mcp.json\`. Use them:
|
|
|
599
701
|
|
|
600
702
|
${MCP_TOOLS_TABLE}
|
|
601
703
|
|
|
704
|
+
## Wiki
|
|
705
|
+
|
|
706
|
+
If \`.maina/wiki/\` exists, use wiki tools for context:
|
|
707
|
+
- \`wikiQuery\` before coding — understand existing patterns and decisions
|
|
708
|
+
- \`wikiStatus\` to check health
|
|
709
|
+
- Wiki articles are loaded automatically as Context Engine Layer 5
|
|
710
|
+
|
|
602
711
|
## Key Commands
|
|
603
712
|
|
|
604
713
|
- \`maina verify\` — run full verification pipeline
|
|
@@ -631,6 +740,172 @@ ${WORKFLOW_ORDER}
|
|
|
631
740
|
## MCP Tools (via .mcp.json)
|
|
632
741
|
${MCP_TOOLS_TABLE}
|
|
633
742
|
|
|
743
|
+
## Wiki
|
|
744
|
+
|
|
745
|
+
If \`.maina/wiki/\` exists, use wiki tools for context:
|
|
746
|
+
- \`wikiQuery\` before coding — understand existing patterns and decisions
|
|
747
|
+
- \`wikiStatus\` to check health
|
|
748
|
+
- Wiki articles are loaded automatically as Context Engine Layer 5
|
|
749
|
+
|
|
750
|
+
## Commands
|
|
751
|
+
- maina verify — run full verification pipeline
|
|
752
|
+
- maina commit — verify + commit
|
|
753
|
+
- maina review — two-stage code review
|
|
754
|
+
- maina context — generate focused codebase context
|
|
755
|
+
|
|
756
|
+
## Conventions
|
|
757
|
+
- Runtime: ${stack.runtime}
|
|
758
|
+
- Test: ${runCmd} test
|
|
759
|
+
- Conventional commits
|
|
760
|
+
- No console.log in production
|
|
761
|
+
- Diff-only: only report findings on changed lines
|
|
762
|
+
- TDD: write tests first, then implement
|
|
763
|
+
`;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
// ── Windsurf ────────────────────────────────────────────────────────────────
|
|
767
|
+
|
|
768
|
+
function buildWindsurfRules(stack: DetectedStack): string {
|
|
769
|
+
const runCmd = stack.runtime === "bun" ? "bun" : "npm";
|
|
770
|
+
return `# Windsurf Rules
|
|
771
|
+
|
|
772
|
+
This repo uses Maina for verification-first development.
|
|
773
|
+
Read \`.maina/constitution.md\` for project DNA.
|
|
774
|
+
|
|
775
|
+
## Workflow Order
|
|
776
|
+
${WORKFLOW_ORDER}
|
|
777
|
+
|
|
778
|
+
## MCP Tools (via .mcp.json)
|
|
779
|
+
${MCP_TOOLS_TABLE}
|
|
780
|
+
|
|
781
|
+
## Wiki
|
|
782
|
+
|
|
783
|
+
If \`.maina/wiki/\` exists, use wiki tools for context:
|
|
784
|
+
- \`wikiQuery\` before coding — understand existing patterns and decisions
|
|
785
|
+
- \`wikiStatus\` to check health
|
|
786
|
+
- Wiki articles are loaded automatically as Context Engine Layer 5
|
|
787
|
+
|
|
788
|
+
## Commands
|
|
789
|
+
- maina verify — run full verification pipeline
|
|
790
|
+
- maina commit — verify + commit
|
|
791
|
+
- maina review — two-stage code review
|
|
792
|
+
- maina context — generate focused codebase context
|
|
793
|
+
|
|
794
|
+
## Conventions
|
|
795
|
+
- Runtime: ${stack.runtime}
|
|
796
|
+
- Test: ${runCmd} test
|
|
797
|
+
- Conventional commits
|
|
798
|
+
- No console.log in production
|
|
799
|
+
- Diff-only: only report findings on changed lines
|
|
800
|
+
- TDD: write tests first, then implement
|
|
801
|
+
`;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
// ── Cline ───────────────────────────────────────────────────────────────────
|
|
805
|
+
|
|
806
|
+
function buildClineRules(stack: DetectedStack): string {
|
|
807
|
+
const runCmd = stack.runtime === "bun" ? "bun" : "npm";
|
|
808
|
+
return `# Cline Rules
|
|
809
|
+
|
|
810
|
+
This repo uses Maina for verification-first development.
|
|
811
|
+
Read \`.maina/constitution.md\` for project DNA.
|
|
812
|
+
|
|
813
|
+
## Workflow Order
|
|
814
|
+
${WORKFLOW_ORDER}
|
|
815
|
+
|
|
816
|
+
## MCP Tools (via .mcp.json)
|
|
817
|
+
${MCP_TOOLS_TABLE}
|
|
818
|
+
|
|
819
|
+
## Wiki
|
|
820
|
+
|
|
821
|
+
If \`.maina/wiki/\` exists, use wiki tools for context:
|
|
822
|
+
- \`wikiQuery\` before coding — understand existing patterns and decisions
|
|
823
|
+
- \`wikiStatus\` to check health
|
|
824
|
+
- Wiki articles are loaded automatically as Context Engine Layer 5
|
|
825
|
+
|
|
826
|
+
## Commands
|
|
827
|
+
- maina verify — run full verification pipeline
|
|
828
|
+
- maina commit — verify + commit
|
|
829
|
+
- maina review — two-stage code review
|
|
830
|
+
- maina context — generate focused codebase context
|
|
831
|
+
|
|
832
|
+
## Conventions
|
|
833
|
+
- Runtime: ${stack.runtime}
|
|
834
|
+
- Test: ${runCmd} test
|
|
835
|
+
- Conventional commits
|
|
836
|
+
- No console.log in production
|
|
837
|
+
- Diff-only: only report findings on changed lines
|
|
838
|
+
- TDD: write tests first, then implement
|
|
839
|
+
`;
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
// ── Continue.dev ─────────────────────────────────────────────────────────────
|
|
843
|
+
|
|
844
|
+
function buildContinueConfig(_stack: DetectedStack): string {
|
|
845
|
+
return `# Continue.dev configuration — auto-generated by maina init
|
|
846
|
+
# See https://docs.continue.dev/reference/config
|
|
847
|
+
|
|
848
|
+
customInstructions: |
|
|
849
|
+
This repo uses Maina for verification-first development.
|
|
850
|
+
Read .maina/constitution.md for project DNA.
|
|
851
|
+
Workflow: ${WORKFLOW_ORDER}
|
|
852
|
+
Always run maina verify before committing.
|
|
853
|
+
Use MCP tools: getContext, verify, checkSlop, reviewCode, suggestTests.
|
|
854
|
+
`;
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
function buildContinueMcpJson(stack: DetectedStack): string {
|
|
858
|
+
const command = stack.runtime === "bun" ? "bunx" : "npx";
|
|
859
|
+
return JSON.stringify(
|
|
860
|
+
{
|
|
861
|
+
maina: {
|
|
862
|
+
command,
|
|
863
|
+
args: ["@mainahq/cli", "--mcp"],
|
|
864
|
+
},
|
|
865
|
+
},
|
|
866
|
+
null,
|
|
867
|
+
2,
|
|
868
|
+
);
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
// ── Roo Code ────────────────────────────────────────────────────────────────
|
|
872
|
+
|
|
873
|
+
function buildRooMcpJson(stack: DetectedStack): string {
|
|
874
|
+
const command = stack.runtime === "bun" ? "bunx" : "npx";
|
|
875
|
+
return JSON.stringify(
|
|
876
|
+
{
|
|
877
|
+
mcpServers: {
|
|
878
|
+
maina: {
|
|
879
|
+
command,
|
|
880
|
+
args: ["@mainahq/cli", "--mcp"],
|
|
881
|
+
},
|
|
882
|
+
},
|
|
883
|
+
},
|
|
884
|
+
null,
|
|
885
|
+
2,
|
|
886
|
+
);
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
function buildRooRules(stack: DetectedStack): string {
|
|
890
|
+
const runCmd = stack.runtime === "bun" ? "bun" : "npm";
|
|
891
|
+
return `# Maina
|
|
892
|
+
|
|
893
|
+
This repo uses [Maina](https://mainahq.com) for verification-first development.
|
|
894
|
+
Read \`.maina/constitution.md\` for project DNA.
|
|
895
|
+
|
|
896
|
+
## Workflow Order
|
|
897
|
+
${WORKFLOW_ORDER}
|
|
898
|
+
|
|
899
|
+
## MCP Tools
|
|
900
|
+
${MCP_TOOLS_TABLE}
|
|
901
|
+
|
|
902
|
+
## Wiki
|
|
903
|
+
|
|
904
|
+
If \`.maina/wiki/\` exists, use wiki tools for context:
|
|
905
|
+
- \`wikiQuery\` before coding — understand existing patterns and decisions
|
|
906
|
+
- \`wikiStatus\` to check health
|
|
907
|
+
- Wiki articles are loaded automatically as Context Engine Layer 5
|
|
908
|
+
|
|
634
909
|
## Commands
|
|
635
910
|
- maina verify — run full verification pipeline
|
|
636
911
|
- maina commit — verify + commit
|
|
@@ -647,6 +922,77 @@ ${MCP_TOOLS_TABLE}
|
|
|
647
922
|
`;
|
|
648
923
|
}
|
|
649
924
|
|
|
925
|
+
// ── Amazon Q ────────────────────────────────────────────────────────────────
|
|
926
|
+
|
|
927
|
+
function buildAmazonQMcpJson(stack: DetectedStack): string {
|
|
928
|
+
const command = stack.runtime === "bun" ? "bunx" : "npx";
|
|
929
|
+
return JSON.stringify(
|
|
930
|
+
{
|
|
931
|
+
mcpServers: {
|
|
932
|
+
maina: {
|
|
933
|
+
command,
|
|
934
|
+
args: ["@mainahq/cli", "--mcp"],
|
|
935
|
+
},
|
|
936
|
+
},
|
|
937
|
+
},
|
|
938
|
+
null,
|
|
939
|
+
2,
|
|
940
|
+
);
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
// ── Aider ───────────────────────────────────────────────────────────────────
|
|
944
|
+
|
|
945
|
+
function buildAiderConfig(_stack: DetectedStack): string {
|
|
946
|
+
return `# Maina conventions — auto-generated by maina init
|
|
947
|
+
read: [CONVENTIONS.md, .maina/constitution.md]
|
|
948
|
+
auto-commits: false
|
|
949
|
+
`;
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
function buildConventionsMd(stack: DetectedStack): string {
|
|
953
|
+
const runCmd = stack.runtime === "bun" ? "bun" : "npm";
|
|
954
|
+
return `# Conventions
|
|
955
|
+
|
|
956
|
+
This repo uses [Maina](https://mainahq.com) for verification-first development.
|
|
957
|
+
Read \`.maina/constitution.md\` for project DNA — stack rules, conventions, and gates.
|
|
958
|
+
|
|
959
|
+
## Maina Workflow
|
|
960
|
+
|
|
961
|
+
Follow this order for every feature:
|
|
962
|
+
\`${WORKFLOW_ORDER}\`
|
|
963
|
+
|
|
964
|
+
## MCP Tools
|
|
965
|
+
|
|
966
|
+
Maina exposes MCP tools — use them in every session:
|
|
967
|
+
|
|
968
|
+
${MCP_TOOLS_TABLE}
|
|
969
|
+
|
|
970
|
+
## Wiki
|
|
971
|
+
|
|
972
|
+
If \`.maina/wiki/\` exists, use wiki tools for context:
|
|
973
|
+
- \`wikiQuery\` before coding — understand existing patterns and decisions
|
|
974
|
+
- \`wikiStatus\` to check health
|
|
975
|
+
- Wiki articles are loaded automatically as Context Engine Layer 5
|
|
976
|
+
|
|
977
|
+
## Key Commands
|
|
978
|
+
|
|
979
|
+
- \`maina verify\` — run full verification pipeline
|
|
980
|
+
- \`maina commit\` — verify + commit
|
|
981
|
+
- \`maina review\` — two-stage code review
|
|
982
|
+
- \`maina context\` — generate focused codebase context
|
|
983
|
+
- \`maina doctor\` — check tool health
|
|
984
|
+
|
|
985
|
+
## Conventions
|
|
986
|
+
|
|
987
|
+
- Runtime: ${stack.runtime}
|
|
988
|
+
- Test: \`${runCmd} test\`
|
|
989
|
+
- Conventional commits (feat, fix, refactor, test, docs, chore)
|
|
990
|
+
- No \`console.log\` in production code
|
|
991
|
+
- Diff-only: only report findings on changed lines
|
|
992
|
+
- TDD always — write tests first
|
|
993
|
+
`;
|
|
994
|
+
}
|
|
995
|
+
|
|
650
996
|
// ── AI-Generated Constitution ───────────────────────────────────────────────
|
|
651
997
|
|
|
652
998
|
function buildProjectSummary(repoRoot: string, stack: DetectedStack): string {
|
|
@@ -839,7 +1185,11 @@ function getFileManifest(
|
|
|
839
1185
|
},
|
|
840
1186
|
{
|
|
841
1187
|
relativePath: ".mcp.json",
|
|
842
|
-
content: buildMcpJson(),
|
|
1188
|
+
content: buildMcpJson(stack),
|
|
1189
|
+
},
|
|
1190
|
+
{
|
|
1191
|
+
relativePath: ".claude/settings.json",
|
|
1192
|
+
content: buildClaudeSettings(stack),
|
|
843
1193
|
},
|
|
844
1194
|
{
|
|
845
1195
|
relativePath: "CLAUDE.md",
|
|
@@ -853,6 +1203,42 @@ function getFileManifest(
|
|
|
853
1203
|
relativePath: ".cursorrules",
|
|
854
1204
|
content: buildCursorRules(stack),
|
|
855
1205
|
},
|
|
1206
|
+
{
|
|
1207
|
+
relativePath: ".windsurfrules",
|
|
1208
|
+
content: buildWindsurfRules(stack),
|
|
1209
|
+
},
|
|
1210
|
+
{
|
|
1211
|
+
relativePath: ".clinerules",
|
|
1212
|
+
content: buildClineRules(stack),
|
|
1213
|
+
},
|
|
1214
|
+
{
|
|
1215
|
+
relativePath: ".continue/config.yaml",
|
|
1216
|
+
content: buildContinueConfig(stack),
|
|
1217
|
+
},
|
|
1218
|
+
{
|
|
1219
|
+
relativePath: ".continue/mcpServers/maina.json",
|
|
1220
|
+
content: buildContinueMcpJson(stack),
|
|
1221
|
+
},
|
|
1222
|
+
{
|
|
1223
|
+
relativePath: ".roo/mcp.json",
|
|
1224
|
+
content: buildRooMcpJson(stack),
|
|
1225
|
+
},
|
|
1226
|
+
{
|
|
1227
|
+
relativePath: ".roo/rules/maina.md",
|
|
1228
|
+
content: buildRooRules(stack),
|
|
1229
|
+
},
|
|
1230
|
+
{
|
|
1231
|
+
relativePath: ".amazonq/mcp.json",
|
|
1232
|
+
content: buildAmazonQMcpJson(stack),
|
|
1233
|
+
},
|
|
1234
|
+
{
|
|
1235
|
+
relativePath: ".aider.conf.yml",
|
|
1236
|
+
content: buildAiderConfig(stack),
|
|
1237
|
+
},
|
|
1238
|
+
{
|
|
1239
|
+
relativePath: "CONVENTIONS.md",
|
|
1240
|
+
content: buildConventionsMd(stack),
|
|
1241
|
+
},
|
|
856
1242
|
];
|
|
857
1243
|
}
|
|
858
1244
|
|
|
@@ -910,6 +1296,7 @@ export async function bootstrap(
|
|
|
910
1296
|
const mainaDir = join(repoRoot, ".maina");
|
|
911
1297
|
const created: string[] = [];
|
|
912
1298
|
const skipped: string[] = [];
|
|
1299
|
+
const updated: string[] = [];
|
|
913
1300
|
|
|
914
1301
|
try {
|
|
915
1302
|
// Detect project stack from package.json
|
|
@@ -950,7 +1337,25 @@ export async function bootstrap(
|
|
|
950
1337
|
mkdirSync(dirPath, { recursive: true });
|
|
951
1338
|
|
|
952
1339
|
if (existsSync(fullPath) && !force) {
|
|
953
|
-
|
|
1340
|
+
// Try to merge maina section for agent files
|
|
1341
|
+
if (
|
|
1342
|
+
MERGEABLE_AGENT_FILES.some((af) => entry.relativePath.endsWith(af))
|
|
1343
|
+
) {
|
|
1344
|
+
const existing = readFileSync(fullPath, "utf-8");
|
|
1345
|
+
if (!existing.includes("## Maina")) {
|
|
1346
|
+
const mainaSection = buildMainaSection(detectedStack);
|
|
1347
|
+
writeFileSync(
|
|
1348
|
+
fullPath,
|
|
1349
|
+
`${existing.trimEnd()}\n\n${mainaSection}`,
|
|
1350
|
+
"utf-8",
|
|
1351
|
+
);
|
|
1352
|
+
updated.push(entry.relativePath);
|
|
1353
|
+
} else {
|
|
1354
|
+
skipped.push(entry.relativePath);
|
|
1355
|
+
}
|
|
1356
|
+
} else {
|
|
1357
|
+
skipped.push(entry.relativePath);
|
|
1358
|
+
}
|
|
954
1359
|
} else {
|
|
955
1360
|
writeFileSync(fullPath, entry.content, "utf-8");
|
|
956
1361
|
created.push(entry.relativePath);
|
|
@@ -973,6 +1378,7 @@ export async function bootstrap(
|
|
|
973
1378
|
value: {
|
|
974
1379
|
created,
|
|
975
1380
|
skipped,
|
|
1381
|
+
updated,
|
|
976
1382
|
directory: mainaDir,
|
|
977
1383
|
detectedStack,
|
|
978
1384
|
detectedTools: detectedToolsList,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"packages": []}
|
|
@@ -11,7 +11,9 @@ export type PromptTask =
|
|
|
11
11
|
| "spec-questions"
|
|
12
12
|
| "design-approaches"
|
|
13
13
|
| "ai-review"
|
|
14
|
-
| "design-hld-lld"
|
|
14
|
+
| "design-hld-lld"
|
|
15
|
+
| "wiki-query"
|
|
16
|
+
| "wiki-compile";
|
|
15
17
|
|
|
16
18
|
const FALLBACK_TEMPLATE = `You are a helpful AI assistant completing the "{{task}}" task.
|
|
17
19
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
You are enhancing a wiki article with natural language descriptions.
|
|
2
|
+
|
|
3
|
+
## Constitution (non-negotiable)
|
|
4
|
+
{{constitution}}
|
|
5
|
+
|
|
6
|
+
## Instructions
|
|
7
|
+
Enhance this wiki article with natural language descriptions. Keep all existing structured data.
|
|
8
|
+
Add a brief overview paragraph and usage context. Do not remove any existing content.
|
|
9
|
+
|
|
10
|
+
Rules:
|
|
11
|
+
1. Preserve ALL existing markdown structure, headings, lists, and wikilinks
|
|
12
|
+
2. Add a concise overview paragraph after the title heading
|
|
13
|
+
3. Add natural language descriptions to sections that are purely data-driven
|
|
14
|
+
4. Infer relationships not visible from code structure alone where possible
|
|
15
|
+
5. Add brief usage examples if the context provides enough information
|
|
16
|
+
6. Keep the tone technical and factual — do not add filler or marketing language
|
|
17
|
+
7. If anything is ambiguous, use [NEEDS CLARIFICATION: specific question]
|
|
18
|
+
|
|
19
|
+
## Input
|
|
20
|
+
{{input}}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
You are answering a question about a codebase using wiki documentation.
|
|
2
|
+
|
|
3
|
+
## Constitution (non-negotiable)
|
|
4
|
+
{{constitution}}
|
|
5
|
+
|
|
6
|
+
## Instructions
|
|
7
|
+
Answer the user's question based on the provided wiki articles.
|
|
8
|
+
|
|
9
|
+
Rules:
|
|
10
|
+
1. Provide a clear, concise answer that directly addresses the question
|
|
11
|
+
2. Cite relevant articles using [[article_path]] notation (e.g., [[modules/core.md]])
|
|
12
|
+
3. If the articles don't contain enough information, say so explicitly
|
|
13
|
+
4. Do NOT guess or hallucinate information not present in the articles
|
|
14
|
+
5. If anything is ambiguous, use [NEEDS CLARIFICATION: specific question]
|
|
15
|
+
6. Prioritize accuracy over completeness
|
|
16
|
+
|
|
17
|
+
## Input
|
|
18
|
+
{{input}}
|