@relipa/ai-flow-kit 0.0.1

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 (204) hide show
  1. package/AIFLOW.md +432 -0
  2. package/CHANGELOG.md +78 -0
  3. package/CONTRIBUTING.md +351 -0
  4. package/IMPLEMENTATION_SUMMARY.md +348 -0
  5. package/QUICK_START.md +392 -0
  6. package/README.md +323 -0
  7. package/bin/aiflow.js +178 -0
  8. package/custom/mcp-presets/README.md +138 -0
  9. package/custom/mcp-presets/backlog.json +15 -0
  10. package/custom/mcp-presets/figma.json +15 -0
  11. package/custom/mcp-presets/google-sheets.json +14 -0
  12. package/custom/mcp-presets/jira.json +16 -0
  13. package/custom/prompts/bug-fix.md +149 -0
  14. package/custom/prompts/feature.md +190 -0
  15. package/custom/prompts/investigation.md +164 -0
  16. package/custom/rules/code-style.md +7 -0
  17. package/custom/rules/java/code-style.md +11 -0
  18. package/custom/rules/java/naming.md +17 -0
  19. package/custom/rules/java/review-checklist.md +36 -0
  20. package/custom/rules/javascript/code-style.md +12 -0
  21. package/custom/rules/javascript/naming.md +14 -0
  22. package/custom/rules/naming.md +9 -0
  23. package/custom/rules/php/code-style.md +10 -0
  24. package/custom/rules/php/naming.md +15 -0
  25. package/custom/rules/review-checklist.md +9 -0
  26. package/custom/skills/figma-to-component/SKILL.md +207 -0
  27. package/custom/skills/generate-spec/SKILL.md +97 -0
  28. package/custom/skills/impact-analysis/SKILL.md +94 -0
  29. package/custom/skills/investigate-bug/SKILL.md +93 -0
  30. package/custom/skills/report-customer/SKILL.md +95 -0
  31. package/custom/skills/review-plan/SKILL.md +158 -0
  32. package/custom/skills/validate-ticket/SKILL.md +240 -0
  33. package/custom/templates/laravel.md +90 -0
  34. package/custom/templates/nextjs.md +89 -0
  35. package/custom/templates/reactjs.md +567 -0
  36. package/custom/templates/spring-boot.md +598 -0
  37. package/custom/templates/vue-nuxt.md +89 -0
  38. package/docs/architecture.md +395 -0
  39. package/docs/cli-reference.md +438 -0
  40. package/docs/configuration.md +412 -0
  41. package/docs/getting-started.md +248 -0
  42. package/docs/troubleshooting.md +587 -0
  43. package/docs/workflows/bug-fix.md +126 -0
  44. package/docs/workflows/feature.md +123 -0
  45. package/docs/workflows/impact-analysis.md +13 -0
  46. package/docs/workflows/investigation.md +13 -0
  47. package/docs/workflows/refactor.md +13 -0
  48. package/index.js +27 -0
  49. package/package.json +70 -0
  50. package/scripts/config.js +317 -0
  51. package/scripts/context.js +117 -0
  52. package/scripts/detect.js +239 -0
  53. package/scripts/doctor.js +48 -0
  54. package/scripts/guide.js +282 -0
  55. package/scripts/hooks/session-start.js +140 -0
  56. package/scripts/init.js +453 -0
  57. package/scripts/memory.js +247 -0
  58. package/scripts/prompt.js +392 -0
  59. package/scripts/remove.js +170 -0
  60. package/scripts/update.js +111 -0
  61. package/scripts/use.js +570 -0
  62. package/scripts/validate.js +303 -0
  63. package/upstream/.claude-plugin/marketplace.json +20 -0
  64. package/upstream/.claude-plugin/plugin.json +20 -0
  65. package/upstream/.codex/INSTALL.md +67 -0
  66. package/upstream/.cursor-plugin/plugin.json +25 -0
  67. package/upstream/.gitattributes +18 -0
  68. package/upstream/.github/FUNDING.yml +3 -0
  69. package/upstream/.github/ISSUE_TEMPLATE/bug_report.md +52 -0
  70. package/upstream/.github/ISSUE_TEMPLATE/config.yml +5 -0
  71. package/upstream/.github/ISSUE_TEMPLATE/feature_request.md +34 -0
  72. package/upstream/.github/ISSUE_TEMPLATE/platform_support.md +23 -0
  73. package/upstream/.github/PULL_REQUEST_TEMPLATE.md +87 -0
  74. package/upstream/.opencode/INSTALL.md +83 -0
  75. package/upstream/.opencode/plugins/superpowers.js +112 -0
  76. package/upstream/.version-bump.json +19 -0
  77. package/upstream/AGENTS.md +1 -0
  78. package/upstream/CHANGELOG.md +13 -0
  79. package/upstream/CLAUDE.md +85 -0
  80. package/upstream/CODE_OF_CONDUCT.md +128 -0
  81. package/upstream/GEMINI.md +2 -0
  82. package/upstream/LICENSE +21 -0
  83. package/upstream/README.md +190 -0
  84. package/upstream/RELEASE-NOTES.md +1096 -0
  85. package/upstream/agents/code-reviewer.md +48 -0
  86. package/upstream/commands/brainstorm.md +5 -0
  87. package/upstream/commands/execute-plan.md +5 -0
  88. package/upstream/commands/write-plan.md +5 -0
  89. package/upstream/docs/README.codex.md +126 -0
  90. package/upstream/docs/README.opencode.md +130 -0
  91. package/upstream/docs/plans/2025-11-22-opencode-support-design.md +294 -0
  92. package/upstream/docs/plans/2025-11-22-opencode-support-implementation.md +1095 -0
  93. package/upstream/docs/plans/2025-11-28-skills-improvements-from-user-feedback.md +711 -0
  94. package/upstream/docs/plans/2026-01-17-visual-brainstorming.md +571 -0
  95. package/upstream/docs/superpowers/plans/2026-01-22-document-review-system.md +301 -0
  96. package/upstream/docs/superpowers/plans/2026-02-19-visual-brainstorming-refactor.md +523 -0
  97. package/upstream/docs/superpowers/plans/2026-03-11-zero-dep-brainstorm-server.md +479 -0
  98. package/upstream/docs/superpowers/plans/2026-03-23-codex-app-compatibility.md +564 -0
  99. package/upstream/docs/superpowers/specs/2026-01-22-document-review-system-design.md +136 -0
  100. package/upstream/docs/superpowers/specs/2026-02-19-visual-brainstorming-refactor-design.md +162 -0
  101. package/upstream/docs/superpowers/specs/2026-03-11-zero-dep-brainstorm-server-design.md +118 -0
  102. package/upstream/docs/superpowers/specs/2026-03-23-codex-app-compatibility-design.md +244 -0
  103. package/upstream/docs/testing.md +303 -0
  104. package/upstream/docs/windows/polyglot-hooks.md +212 -0
  105. package/upstream/gemini-extension.json +6 -0
  106. package/upstream/hooks/hooks-cursor.json +10 -0
  107. package/upstream/hooks/hooks.json +16 -0
  108. package/upstream/hooks/run-hook.cmd +46 -0
  109. package/upstream/hooks/session-start +57 -0
  110. package/upstream/package.json +6 -0
  111. package/upstream/scripts/bump-version.sh +220 -0
  112. package/upstream/skills/brainstorming/SKILL.md +164 -0
  113. package/upstream/skills/brainstorming/scripts/frame-template.html +214 -0
  114. package/upstream/skills/brainstorming/scripts/helper.js +88 -0
  115. package/upstream/skills/brainstorming/scripts/server.cjs +354 -0
  116. package/upstream/skills/brainstorming/scripts/start-server.sh +148 -0
  117. package/upstream/skills/brainstorming/scripts/stop-server.sh +56 -0
  118. package/upstream/skills/brainstorming/spec-document-reviewer-prompt.md +49 -0
  119. package/upstream/skills/brainstorming/visual-companion.md +287 -0
  120. package/upstream/skills/dispatching-parallel-agents/SKILL.md +182 -0
  121. package/upstream/skills/executing-plans/SKILL.md +70 -0
  122. package/upstream/skills/finishing-a-development-branch/SKILL.md +200 -0
  123. package/upstream/skills/receiving-code-review/SKILL.md +213 -0
  124. package/upstream/skills/requesting-code-review/SKILL.md +105 -0
  125. package/upstream/skills/requesting-code-review/code-reviewer.md +146 -0
  126. package/upstream/skills/subagent-driven-development/SKILL.md +277 -0
  127. package/upstream/skills/subagent-driven-development/code-quality-reviewer-prompt.md +26 -0
  128. package/upstream/skills/subagent-driven-development/implementer-prompt.md +113 -0
  129. package/upstream/skills/subagent-driven-development/spec-reviewer-prompt.md +61 -0
  130. package/upstream/skills/systematic-debugging/CREATION-LOG.md +119 -0
  131. package/upstream/skills/systematic-debugging/SKILL.md +296 -0
  132. package/upstream/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
  133. package/upstream/skills/systematic-debugging/condition-based-waiting.md +115 -0
  134. package/upstream/skills/systematic-debugging/defense-in-depth.md +122 -0
  135. package/upstream/skills/systematic-debugging/find-polluter.sh +63 -0
  136. package/upstream/skills/systematic-debugging/root-cause-tracing.md +169 -0
  137. package/upstream/skills/systematic-debugging/test-academic.md +14 -0
  138. package/upstream/skills/systematic-debugging/test-pressure-1.md +58 -0
  139. package/upstream/skills/systematic-debugging/test-pressure-2.md +68 -0
  140. package/upstream/skills/systematic-debugging/test-pressure-3.md +69 -0
  141. package/upstream/skills/test-driven-development/SKILL.md +371 -0
  142. package/upstream/skills/test-driven-development/testing-anti-patterns.md +299 -0
  143. package/upstream/skills/using-git-worktrees/SKILL.md +218 -0
  144. package/upstream/skills/using-superpowers/SKILL.md +117 -0
  145. package/upstream/skills/using-superpowers/references/codex-tools.md +100 -0
  146. package/upstream/skills/using-superpowers/references/copilot-tools.md +52 -0
  147. package/upstream/skills/using-superpowers/references/gemini-tools.md +33 -0
  148. package/upstream/skills/verification-before-completion/SKILL.md +139 -0
  149. package/upstream/skills/writing-plans/SKILL.md +152 -0
  150. package/upstream/skills/writing-plans/plan-document-reviewer-prompt.md +49 -0
  151. package/upstream/skills/writing-skills/SKILL.md +655 -0
  152. package/upstream/skills/writing-skills/anthropic-best-practices.md +1150 -0
  153. package/upstream/skills/writing-skills/examples/CLAUDE_MD_TESTING.md +189 -0
  154. package/upstream/skills/writing-skills/graphviz-conventions.dot +172 -0
  155. package/upstream/skills/writing-skills/persuasion-principles.md +187 -0
  156. package/upstream/skills/writing-skills/render-graphs.js +168 -0
  157. package/upstream/skills/writing-skills/testing-skills-with-subagents.md +384 -0
  158. package/upstream/tests/brainstorm-server/package-lock.json +36 -0
  159. package/upstream/tests/brainstorm-server/package.json +10 -0
  160. package/upstream/tests/brainstorm-server/server.test.js +427 -0
  161. package/upstream/tests/brainstorm-server/windows-lifecycle.test.sh +351 -0
  162. package/upstream/tests/brainstorm-server/ws-protocol.test.js +392 -0
  163. package/upstream/tests/claude-code/README.md +158 -0
  164. package/upstream/tests/claude-code/analyze-token-usage.py +168 -0
  165. package/upstream/tests/claude-code/run-skill-tests.sh +187 -0
  166. package/upstream/tests/claude-code/test-document-review-system.sh +177 -0
  167. package/upstream/tests/claude-code/test-helpers.sh +202 -0
  168. package/upstream/tests/claude-code/test-subagent-driven-development-integration.sh +314 -0
  169. package/upstream/tests/claude-code/test-subagent-driven-development.sh +165 -0
  170. package/upstream/tests/explicit-skill-requests/prompts/action-oriented.txt +3 -0
  171. package/upstream/tests/explicit-skill-requests/prompts/after-planning-flow.txt +17 -0
  172. package/upstream/tests/explicit-skill-requests/prompts/claude-suggested-it.txt +11 -0
  173. package/upstream/tests/explicit-skill-requests/prompts/i-know-what-sdd-means.txt +8 -0
  174. package/upstream/tests/explicit-skill-requests/prompts/mid-conversation-execute-plan.txt +3 -0
  175. package/upstream/tests/explicit-skill-requests/prompts/please-use-brainstorming.txt +1 -0
  176. package/upstream/tests/explicit-skill-requests/prompts/skip-formalities.txt +3 -0
  177. package/upstream/tests/explicit-skill-requests/prompts/subagent-driven-development-please.txt +1 -0
  178. package/upstream/tests/explicit-skill-requests/prompts/use-systematic-debugging.txt +1 -0
  179. package/upstream/tests/explicit-skill-requests/run-all.sh +70 -0
  180. package/upstream/tests/explicit-skill-requests/run-claude-describes-sdd.sh +100 -0
  181. package/upstream/tests/explicit-skill-requests/run-extended-multiturn-test.sh +113 -0
  182. package/upstream/tests/explicit-skill-requests/run-haiku-test.sh +144 -0
  183. package/upstream/tests/explicit-skill-requests/run-multiturn-test.sh +143 -0
  184. package/upstream/tests/explicit-skill-requests/run-test.sh +136 -0
  185. package/upstream/tests/opencode/run-tests.sh +163 -0
  186. package/upstream/tests/opencode/setup.sh +88 -0
  187. package/upstream/tests/opencode/test-plugin-loading.sh +82 -0
  188. package/upstream/tests/opencode/test-priority.sh +198 -0
  189. package/upstream/tests/opencode/test-tools.sh +104 -0
  190. package/upstream/tests/skill-triggering/prompts/dispatching-parallel-agents.txt +8 -0
  191. package/upstream/tests/skill-triggering/prompts/executing-plans.txt +1 -0
  192. package/upstream/tests/skill-triggering/prompts/requesting-code-review.txt +3 -0
  193. package/upstream/tests/skill-triggering/prompts/systematic-debugging.txt +11 -0
  194. package/upstream/tests/skill-triggering/prompts/test-driven-development.txt +7 -0
  195. package/upstream/tests/skill-triggering/prompts/writing-plans.txt +10 -0
  196. package/upstream/tests/skill-triggering/run-all.sh +60 -0
  197. package/upstream/tests/skill-triggering/run-test.sh +88 -0
  198. package/upstream/tests/subagent-driven-dev/go-fractals/design.md +81 -0
  199. package/upstream/tests/subagent-driven-dev/go-fractals/plan.md +172 -0
  200. package/upstream/tests/subagent-driven-dev/go-fractals/scaffold.sh +45 -0
  201. package/upstream/tests/subagent-driven-dev/run-test.sh +106 -0
  202. package/upstream/tests/subagent-driven-dev/svelte-todo/design.md +70 -0
  203. package/upstream/tests/subagent-driven-dev/svelte-todo/plan.md +222 -0
  204. package/upstream/tests/subagent-driven-dev/svelte-todo/scaffold.sh +46 -0
@@ -0,0 +1,123 @@
1
+ # Feature Development Workflow
2
+
3
+ > See the full workflow at [AIFLOW.md](../../AIFLOW.md)
4
+ > **Gates must pass in order: 1 → 2 → 3 → 4 → 5**
5
+
6
+ ---
7
+
8
+ ## Step 1: Load ticket & AI analyzes (Gate 1)
9
+
10
+ ```bash
11
+ aiflow use PROJ-33 # from Backlog/Jira
12
+ claude # AI auto-starts Gate 1
13
+ ```
14
+
15
+ AI will **automatically**:
16
+ 1. Load ticket info from Backlog/Jira
17
+ 2. Read source code — understand architecture, related files, patterns
18
+ 3. Ask clarifying questions if anything is unclear (one at a time)
19
+ 4. Output `plan/[ticket-id]/requirement.md` containing:
20
+ - Requirements summary (AI's understanding)
21
+ - Source code analysis (related files, data flow)
22
+ - **Proposed solution** with options and recommendation
23
+ - **Impact analysis** — affected areas, risks
24
+ - **Effort estimate** (S/M/L/XL)
25
+ - Testing plan
26
+
27
+ **PM needs to prepare on the ticket:**
28
+ ```markdown
29
+ ## Description
30
+ Clear business requirement. Who uses it, and for what purpose.
31
+
32
+ ## Acceptance Criteria
33
+ - [ ] [Condition for completion 1]
34
+ - [ ] [Condition for completion 2]
35
+
36
+ ## Mockup / Wireframe
37
+ [Link or UI description]
38
+
39
+ ## Context
40
+ Constraints, business rules specially requiring attention.
41
+ ```
42
+
43
+ **If ticket content is unclear:** AI will ask questions based on source code analysis — not just checking format.
44
+
45
+ **When satisfied with the requirement document, type:**
46
+ ```
47
+ APPROVED
48
+ ```
49
+
50
+ ---
51
+
52
+ ## Step 2: Review Implementation Plan (Gate 2)
53
+
54
+ AI generates a detailed implementation plan:
55
+ - TDD task breakdown (test first → implement → verify)
56
+ - Commit strategy (small, focused commits)
57
+ - Test commands
58
+
59
+ **When agreed, type:**
60
+ ```
61
+ APPROVED
62
+ ```
63
+
64
+ **CODE WILL NOT BE GENERATED BEFORE RECEIVING "APPROVED".**
65
+
66
+ ---
67
+
68
+ ## Step 3: AI Generate Code (Gate 3)
69
+
70
+ AI performs automatically:
71
+ 1. Complex feature (3+ files): `superpowers:subagent-driven-development`
72
+ 2. Write tests FIRST → run → confirm FAIL
73
+ 3. Implement → tests PASS
74
+ 4. Commit each small step
75
+
76
+ Developer doesn't need to do anything at this step — just monitor.
77
+
78
+ ---
79
+
80
+ ## Step 4: Review Summary (Gate 4)
81
+
82
+ AI runs:
83
+ 1. `superpowers:verification-before-completion` — all tests PASS
84
+ 2. `impact-analysis` — no breaking changes outside of scope
85
+ 3. Review checklist — all items ticked
86
+ 4. Create `plan/[ticket-id]/summary.md`
87
+
88
+ AI displays summary and waits for developer review.
89
+
90
+ **If OK, type:**
91
+ ```
92
+ APPROVED
93
+ ```
94
+
95
+ **If there are bugs, type:**
96
+ ```
97
+ BUG: [specific description]
98
+ ```
99
+ - Coding bug → AI fixes → repeat Gate 4
100
+ - Requirement bug → AI returns to Gate 1, update requirement doc
101
+
102
+ ---
103
+
104
+ ## Step 5: Peer Review & PR (Gate 5)
105
+
106
+ AI invokes `superpowers:requesting-code-review` and guides PR creation.
107
+
108
+ ```bash
109
+ git push origin feature/PROJ-33-feature-name
110
+ # Create PR with full description following the template in AIFLOW.md
111
+ ```
112
+
113
+ Peer reviewer uses the `superpowers:receiving-code-review` skill during review.
114
+
115
+ ---
116
+
117
+ ## Completion Checklist
118
+
119
+ - [ ] Gate 1 APPROVED — requirement doc with solution, impact, estimate
120
+ - [ ] Gate 2 APPROVED — implementation plan confirmed by developer
121
+ - [ ] Gate 3 done — code + tests are green
122
+ - [ ] Gate 4 APPROVED — summary + checklist complete
123
+ - [ ] Gate 5 done — PR is peer-reviewed and merged
@@ -0,0 +1,13 @@
1
+ # Impact Analysis Workflow
2
+
3
+ > See the full workflow at [AIFLOW.md](../../AIFLOW.md)
4
+
5
+ ## Quick start
6
+
7
+ ```bash
8
+ aiflow use PROJ-33
9
+ aiflow prompt impact-analysis
10
+ claude
11
+ ```
12
+
13
+ See the details of each Gate in AIFLOW.md — Section "Workflow by Task Type".
@@ -0,0 +1,13 @@
1
+ # Investigation Workflow
2
+
3
+ > See the full workflow at [AIFLOW.md](../../AIFLOW.md)
4
+
5
+ ## Quick start
6
+
7
+ ```bash
8
+ aiflow use PROJ-33
9
+ aiflow prompt investigation
10
+ claude
11
+ ```
12
+
13
+ See the details of each Gate in AIFLOW.md — Section "Workflow by Task Type".
@@ -0,0 +1,13 @@
1
+ # Refactor Workflow
2
+
3
+ > See the full workflow at [AIFLOW.md](../../AIFLOW.md)
4
+
5
+ ## Quick start
6
+
7
+ ```bash
8
+ aiflow use PROJ-33
9
+ aiflow prompt refactor
10
+ claude
11
+ ```
12
+
13
+ See the details of each Gate in AIFLOW.md — Section "Workflow by Task Type".
package/index.js ADDED
@@ -0,0 +1,27 @@
1
+ // AI Flow Kit - Main Entry Point
2
+ // Exports core utilities for programmatic use
3
+
4
+ module.exports = {
5
+ // Configuration
6
+ ConfigManager: require('./scripts/config'),
7
+
8
+ // Task Detection
9
+ TaskDetector: require('./scripts/detect'),
10
+
11
+ // Commands (as modules)
12
+ init: require('./scripts/init'),
13
+ update: require('./scripts/update'),
14
+ doctor: require('./scripts/doctor'),
15
+ use: require('./scripts/use'),
16
+ context: require('./scripts/context'),
17
+ prompt: require('./scripts/prompt'),
18
+ remove: require('./scripts/remove'),
19
+ guide: require('./scripts/guide'),
20
+
21
+ // Utilities
22
+ validate: require('./scripts/validate'),
23
+ memory: require('./scripts/memory'),
24
+
25
+ // Version
26
+ version: require('./package.json').version
27
+ };
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@relipa/ai-flow-kit",
3
+ "version": "0.0.1",
4
+ "description": "All-in-one AI Flow Kit for team development with Claude AI - skills, templates, and MCP adapters",
5
+ "author": "Relipa AI Team",
6
+ "publishConfig": {
7
+ "access": "public",
8
+ "registry": "https://registry.npmjs.com/"
9
+ },
10
+ "license": "ISC",
11
+ "type": "commonjs",
12
+ "main": "index.js",
13
+ "bin": {
14
+ "aiflow": "./bin/aiflow.js"
15
+ },
16
+ "files": [
17
+ "bin",
18
+ "custom",
19
+ "scripts",
20
+ "upstream",
21
+ "docs",
22
+ "package.json",
23
+ "index.js",
24
+ "README.md",
25
+ "QUICK_START.md",
26
+ "AIFLOW.md",
27
+ "CONTRIBUTING.md",
28
+ "IMPLEMENTATION_SUMMARY.md",
29
+ "CHANGELOG.md"
30
+ ],
31
+ "keywords": [
32
+ "ai",
33
+ "claude",
34
+ "development",
35
+ "workflow",
36
+ "superpowers",
37
+ "mcp",
38
+ "team",
39
+ "productivity"
40
+ ],
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "https://gitlab.relipa.vn/ai/ai-flow-kit"
44
+ },
45
+ "bugs": {
46
+ "url": "https://gitlab.relipa.vn/ai/ai-flow-kit/-/issues"
47
+ },
48
+ "homepage": "https://gitlab.relipa.vn/ai/ai-flow-kit",
49
+ "engines": {
50
+ "node": ">=14.0.0",
51
+ "npm": ">=6.0.0"
52
+ },
53
+ "scripts": {
54
+ "aiflow": "node bin/aiflow.js",
55
+ "test": "echo \"Add tests in future\" && exit 0",
56
+ "lint": "echo \"Add linting in future\" && exit 0",
57
+ "docs": "echo \"Documentation available in ./docs\"",
58
+ "publish": "npm publish"
59
+ },
60
+ "dependencies": {
61
+ "@inquirer/prompts": "^8.3.2",
62
+ "chalk": "^4.1.2",
63
+ "commander": "^14.0.3",
64
+ "fs-extra": "^11.3.4",
65
+ "semver": "^7.7.4"
66
+ },
67
+ "devDependencies": {
68
+ "typescript": "^6.0.2"
69
+ }
70
+ }
@@ -0,0 +1,317 @@
1
+ const fs = require('fs-extra');
2
+ const path = require('path');
3
+
4
+ class ConfigManager {
5
+ constructor() {
6
+ this.globalConfigPath = path.join(
7
+ process.env.HOME || process.env.USERPROFILE || process.env.HOMEPATH,
8
+ '.claude',
9
+ 'ai-flow-kit.json'
10
+ );
11
+ this.projectConfigPath = path.join(process.cwd(), '.aiflowrc.json');
12
+ this.cache = {};
13
+ }
14
+
15
+ /**
16
+ * Load configuration with proper priority:
17
+ * 1. Environment variables
18
+ * 2. CLI flags
19
+ * 3. Project config (.aiflowrc.json)
20
+ * 4. Global config
21
+ * 5. Defaults
22
+ */
23
+ async load(cliFlags = {}) {
24
+ const defaults = this.getDefaults();
25
+ const globalConfig = await this.loadFile(this.globalConfigPath) || {};
26
+ const projectConfig = await this.loadFile(this.projectConfigPath) || {};
27
+ const envConfig = this.loadFromEnv();
28
+
29
+ // Merge with proper precedence
30
+ this.cache = {
31
+ ...defaults,
32
+ ...globalConfig,
33
+ ...projectConfig,
34
+ ...envConfig,
35
+ ...cliFlags
36
+ };
37
+
38
+ return this.cache;
39
+ }
40
+
41
+ /**
42
+ * Get configuration value with nested path support
43
+ * e.g., get('mcp.timeout') → 30000
44
+ */
45
+ get(path, defaultValue = null) {
46
+ const parts = path.split('.');
47
+ let value = this.cache;
48
+
49
+ for (const part of parts) {
50
+ if (value && typeof value === 'object' && part in value) {
51
+ value = value[part];
52
+ } else {
53
+ return defaultValue;
54
+ }
55
+ }
56
+
57
+ return value;
58
+ }
59
+
60
+ /**
61
+ * Load environment variables with AIFLOW_ prefix
62
+ */
63
+ loadFromEnv() {
64
+ const envConfig = {};
65
+
66
+ // Map environment variables to config
67
+ const envMap = {
68
+ 'AIFLOW_TEAM': 'team',
69
+ 'AIFLOW_MODEL': 'defaultModel',
70
+ 'AIFLOW_ADAPTERS': 'adapters',
71
+ 'AIFLOW_FRAMEWORKS': 'frameworks',
72
+ 'AIFLOW_AUTO_DETECT': 'autoDetectTasks',
73
+ 'AIFLOW_STRICT_MODE': 'strictMode',
74
+ 'AIFLOW_DEBUG': 'debug',
75
+ 'AIFLOW_VERBOSE': 'verbose'
76
+ };
77
+
78
+ for (const [envKey, configKey] of Object.entries(envMap)) {
79
+ if (process.env[envKey]) {
80
+ const value = process.env[envKey];
81
+ // Parse comma-separated lists
82
+ if (configKey === 'adapters' || configKey === 'frameworks') {
83
+ envConfig[configKey] = value.split(',').map(s => s.trim());
84
+ }
85
+ // Parse booleans
86
+ else if (value === 'true' || value === 'false') {
87
+ envConfig[configKey] = value === 'true';
88
+ }
89
+ // Parse numbers
90
+ else if (!isNaN(value)) {
91
+ envConfig[configKey] = parseInt(value);
92
+ }
93
+ else {
94
+ envConfig[configKey] = value;
95
+ }
96
+ }
97
+ }
98
+
99
+ return envConfig;
100
+ }
101
+
102
+ /**
103
+ * Load configuration from file
104
+ */
105
+ async loadFile(filePath) {
106
+ try {
107
+ if (await fs.pathExists(filePath)) {
108
+ return await fs.readJson(filePath);
109
+ }
110
+ } catch (err) {
111
+ console.warn(`Warning: Could not load config from ${filePath}`);
112
+ }
113
+ return null;
114
+ }
115
+
116
+ /**
117
+ * Save project configuration
118
+ */
119
+ async saveProject(config) {
120
+ await fs.ensureDir(path.dirname(this.projectConfigPath));
121
+ await fs.writeJson(this.projectConfigPath, config, { spaces: 2 });
122
+ }
123
+
124
+ /**
125
+ * Save global configuration
126
+ */
127
+ async saveGlobal(config) {
128
+ await fs.ensureDir(path.dirname(this.globalConfigPath));
129
+ await fs.writeJson(this.globalConfigPath, config, { spaces: 2 });
130
+ }
131
+
132
+ /**
133
+ * Default configuration
134
+ */
135
+ getDefaults() {
136
+ return {
137
+ team: 'default-team',
138
+ description: 'Default team configuration',
139
+ adapters: [],
140
+ frameworks: [],
141
+ customSkills: [],
142
+ defaultModel: 'claude-opus-4-6',
143
+ autoDetectTasks: true,
144
+ strictMode: false,
145
+ contextTemplate: 'standard',
146
+ debug: false,
147
+ verbose: false,
148
+
149
+ // MCP Configuration
150
+ mcp: {
151
+ timeout: 30000,
152
+ retries: 3,
153
+ fallback: 'manual'
154
+ },
155
+
156
+ // Context Configuration
157
+ context: {
158
+ includeGitHistory: true,
159
+ includeFileTree: true,
160
+ maxFileSize: 1000000,
161
+ cacheContexts: true,
162
+ cacheTTL: 86400
163
+ },
164
+
165
+ // Prompting Configuration
166
+ prompting: {
167
+ language: 'english',
168
+ detail: 'comprehensive',
169
+ examples: true,
170
+ bestPractices: true,
171
+ warningLevel: 'medium'
172
+ },
173
+
174
+ // Validation Configuration
175
+ validation: {
176
+ enabled: true,
177
+ ruleSet: 'default',
178
+ autoFix: false,
179
+ reportLevel: 'warning'
180
+ },
181
+
182
+ // Task Detection
183
+ detection: {
184
+ confidence_threshold: 0.8,
185
+ fallback: 'ask',
186
+ debug: false
187
+ },
188
+
189
+ // Memory System
190
+ memory: {
191
+ enabled: true,
192
+ autoLoadRelevant: true,
193
+ maxMemorySize: 1000000,
194
+ persistPath: '.aiflow/memory'
195
+ }
196
+ };
197
+ }
198
+
199
+ /**
200
+ * Validate configuration
201
+ */
202
+ validate(config) {
203
+ const errors = [];
204
+
205
+ if (config.adapters && !Array.isArray(config.adapters)) {
206
+ errors.push('adapters must be an array');
207
+ }
208
+
209
+ if (config.frameworks && !Array.isArray(config.frameworks)) {
210
+ errors.push('frameworks must be an array');
211
+ }
212
+
213
+ if (config.defaultModel && typeof config.defaultModel !== 'string') {
214
+ errors.push('defaultModel must be a string');
215
+ }
216
+
217
+ if (typeof config.autoDetectTasks !== 'boolean') {
218
+ errors.push('autoDetectTasks must be boolean');
219
+ }
220
+
221
+ if (typeof config.strictMode !== 'boolean') {
222
+ errors.push('strictMode must be boolean');
223
+ }
224
+
225
+ if (config.mcp && typeof config.mcp !== 'object') {
226
+ errors.push('mcp must be an object');
227
+ }
228
+
229
+ return {
230
+ valid: errors.length === 0,
231
+ errors
232
+ };
233
+ }
234
+
235
+ /**
236
+ * Get all configured adapters
237
+ */
238
+ getAdapters() {
239
+ return this.get('adapters', []);
240
+ }
241
+
242
+ /**
243
+ * Get all configured frameworks
244
+ */
245
+ getFrameworks() {
246
+ return this.get('frameworks', []);
247
+ }
248
+
249
+ /**
250
+ * Check if adapter is configured
251
+ */
252
+ hasAdapter(name) {
253
+ return this.getAdapters().includes(name);
254
+ }
255
+
256
+ /**
257
+ * Check if framework is configured
258
+ */
259
+ hasFramework(name) {
260
+ return this.getFrameworks().includes(name);
261
+ }
262
+
263
+ /**
264
+ * Get configured custom skills
265
+ */
266
+ getCustomSkills() {
267
+ return this.get('customSkills', []);
268
+ }
269
+
270
+ /**
271
+ * Check if in strict mode
272
+ */
273
+ isStrictMode() {
274
+ return this.get('strictMode', false);
275
+ }
276
+
277
+ /**
278
+ * Check if auto-detect is enabled
279
+ */
280
+ isAutoDetectEnabled() {
281
+ return this.get('autoDetectTasks', true);
282
+ }
283
+
284
+ /**
285
+ * Merge custom config with defaults
286
+ */
287
+ merge(customConfig) {
288
+ return { ...this.getDefaults(), ...customConfig };
289
+ }
290
+
291
+ /**
292
+ * Create template config for getting started
293
+ */
294
+ getTemplateConfig(framework = 'generic', adapters = []) {
295
+ return {
296
+ team: 'my-team',
297
+ description: `Configuration for team projects`,
298
+ adapters: adapters.length > 0 ? adapters : [],
299
+ frameworks: framework !== 'generic' ? [framework] : [],
300
+ customSkills: ['investigate-bug', 'impact-analysis'],
301
+ defaultModel: 'claude-opus-4-6',
302
+ autoDetectTasks: true,
303
+ strictMode: false,
304
+ contextTemplate: 'standard',
305
+ prompting: {
306
+ language: 'english',
307
+ detail: 'comprehensive'
308
+ },
309
+ validation: {
310
+ enabled: true,
311
+ ruleSet: 'default'
312
+ }
313
+ };
314
+ }
315
+ }
316
+
317
+ module.exports = ConfigManager;
@@ -0,0 +1,117 @@
1
+ const fs = require('fs-extra');
2
+ const path = require('path');
3
+ const chalk = require('chalk');
4
+
5
+ const PROJECT_DIR = process.cwd();
6
+ const CONTEXT_DIR = path.join(PROJECT_DIR, '.claude', 'context');
7
+ const HISTORY_DIR = path.join(CONTEXT_DIR, 'history');
8
+ const CURRENT_FILE = path.join(CONTEXT_DIR, 'current.json');
9
+
10
+ // ──────────────────────────────────────────────────────────────
11
+ // Entry point — called from bin/aiflow.js
12
+ // ──────────────────────────────────────────────────────────────
13
+
14
+ module.exports = async function context(action, options = {}) {
15
+ // Normalise: commander passes the positional arg as `action`,
16
+ // but flags like --list/--show may also indicate the action.
17
+ const cmd = action || (options.list ? 'list' : options.show ? 'show' : null);
18
+
19
+ try {
20
+ if (cmd === 'list' || options.list) return await listContexts();
21
+ if (cmd === 'show' || options.show) return await showCurrent();
22
+ if (cmd === 'save' || options.save) return await saveCurrent(options.save || cmd);
23
+ if (options.load) return await loadContext(options.load);
24
+ if (options.delete) return await deleteContext(options.delete);
25
+ if (cmd === 'clear' || options.clear) return await clearContexts();
26
+
27
+ console.log(chalk.yellow('Usage: aiflow context <list|show|save <name>|clear>'));
28
+ console.log(chalk.gray(' aiflow context --load <name>'));
29
+ console.log(chalk.gray(' aiflow context --delete <name>'));
30
+ } catch (err) {
31
+ console.error(chalk.red(`Error: ${err.message}`));
32
+ }
33
+ };
34
+
35
+ // ──────────────────────────────────────────────────────────────
36
+ // Commands
37
+ // ──────────────────────────────────────────────────────────────
38
+
39
+ async function listContexts() {
40
+ await fs.ensureDir(HISTORY_DIR);
41
+ const files = (await fs.readdir(HISTORY_DIR)).filter(f => f.endsWith('.json'));
42
+
43
+ if (!files.length) {
44
+ console.log(chalk.gray('No saved contexts.'));
45
+ return;
46
+ }
47
+
48
+ console.log(chalk.cyan('\nSaved contexts:\n'));
49
+ for (const file of files) {
50
+ const name = file.replace(/\.json$/, '');
51
+ const ctx = await fs.readJson(path.join(HISTORY_DIR, file)).catch(() => ({}));
52
+ const label = ctx.title ? ctx.title.substring(0, 60) : '(no title)';
53
+ console.log(` ${chalk.white(name.padEnd(20))} ${chalk.gray(label)}`);
54
+ }
55
+ console.log();
56
+ }
57
+
58
+ async function showCurrent() {
59
+ if (!(await fs.pathExists(CURRENT_FILE))) {
60
+ console.log(chalk.yellow('No current context. Run `aiflow use <ticket>` first.'));
61
+ return;
62
+ }
63
+ const ctx = await fs.readJson(CURRENT_FILE);
64
+ console.log(chalk.cyan('\nCurrent context:\n'));
65
+ console.log(JSON.stringify(ctx, null, 2));
66
+ }
67
+
68
+ async function saveCurrent(name) {
69
+ if (!name || name === 'save') {
70
+ console.log(chalk.red('Provide a name: aiflow context save <name>'));
71
+ return;
72
+ }
73
+ if (!(await fs.pathExists(CURRENT_FILE))) {
74
+ console.log(chalk.yellow('No current context to save. Run `aiflow use <ticket>` first.'));
75
+ return;
76
+ }
77
+ await fs.ensureDir(HISTORY_DIR);
78
+ const dest = path.join(HISTORY_DIR, `${sanitize(name)}.json`);
79
+ await fs.copy(CURRENT_FILE, dest);
80
+ console.log(chalk.green(`✓ Context saved as: ${name}`));
81
+ }
82
+
83
+ async function loadContext(name) {
84
+ await fs.ensureDir(HISTORY_DIR);
85
+ const src = path.join(HISTORY_DIR, `${sanitize(name)}.json`);
86
+ if (!(await fs.pathExists(src))) {
87
+ console.log(chalk.red(`Context not found: ${name}`));
88
+ return;
89
+ }
90
+ await fs.ensureDir(CONTEXT_DIR);
91
+ await fs.copy(src, CURRENT_FILE, { overwrite: true });
92
+ console.log(chalk.green(`✓ Loaded context: ${name}`));
93
+ }
94
+
95
+ async function deleteContext(name) {
96
+ const target = path.join(HISTORY_DIR, `${sanitize(name)}.json`);
97
+ if (!(await fs.pathExists(target))) {
98
+ console.log(chalk.yellow(`Context not found: ${name}`));
99
+ return;
100
+ }
101
+ await fs.remove(target);
102
+ console.log(chalk.green(`✓ Deleted context: ${name}`));
103
+ }
104
+
105
+ async function clearContexts() {
106
+ await fs.ensureDir(HISTORY_DIR);
107
+ await fs.emptyDir(HISTORY_DIR);
108
+ console.log(chalk.green('✓ Cleared all saved contexts.'));
109
+ }
110
+
111
+ // ──────────────────────────────────────────────────────────────
112
+ // Helpers
113
+ // ──────────────────────────────────────────────────────────────
114
+
115
+ function sanitize(name) {
116
+ return name.toLowerCase().replace(/[^\w-]/g, '-').replace(/-+/g, '-').substring(0, 60);
117
+ }