@decohere/scaffold 0.0.1-dev.18 → 0.0.1-dev.80

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 (240) hide show
  1. package/commonjs/src/add-api.action.js +39 -0
  2. package/commonjs/src/add-api.command.js +41 -0
  3. package/commonjs/src/add.command.js +24 -0
  4. package/commonjs/src/add.module.js +26 -0
  5. package/commonjs/src/cli.js +9 -0
  6. package/commonjs/src/create.command.js +24 -0
  7. package/commonjs/src/create.module.js +26 -0
  8. package/commonjs/src/domain/prompt.js +64 -0
  9. package/commonjs/src/index.js +38 -0
  10. package/commonjs/src/models/compose.model.js +150 -0
  11. package/commonjs/src/models/config-yaml.model.js +88 -0
  12. package/commonjs/src/models/const.js +32 -0
  13. package/commonjs/src/models/dev-container.model.js +116 -0
  14. package/commonjs/src/models/docker-image.model.js +259 -0
  15. package/commonjs/src/models/env-file.model.js +50 -0
  16. package/commonjs/src/models/gitignore.model.js +43 -0
  17. package/commonjs/src/models/launch-json.model.js +74 -0
  18. package/commonjs/src/models/package-json.model.js +149 -0
  19. package/commonjs/src/models/project.model.js +134 -0
  20. package/commonjs/src/models/source-file.js +6 -0
  21. package/commonjs/src/models/tsconfig.model.js +34 -0
  22. package/commonjs/src/models/vitest-config.model.js +35 -0
  23. package/commonjs/src/models/vscode-settings.model.js +31 -0
  24. package/commonjs/src/program.js +57 -0
  25. package/commonjs/src/resolve-target-dir.js +19 -0
  26. package/commonjs/src/services/scaffold.service.js +62 -0
  27. package/commonjs/src/version.js +57 -0
  28. package/commonjs/src/webapi/api-name.js +95 -0
  29. package/commonjs/src/webapi/cli-options.js +101 -0
  30. package/commonjs/src/webapi/const.js +50 -0
  31. package/commonjs/src/webapi/create-api.js +237 -0
  32. package/commonjs/src/webapi/devcontainer/codebase-rag-mcp.js +166 -0
  33. package/commonjs/src/webapi/devcontainer/codebase-rag-mcp.ts +182 -0
  34. package/commonjs/src/webapi/devcontainer/host-scripts.js +52 -0
  35. package/commonjs/src/webapi/devcontainer/templates/codebase-rag.env.example +3 -0
  36. package/commonjs/src/webapi/devcontainer/templates/initialize.sh +169 -0
  37. package/commonjs/src/webapi/devcontainer/templates/post-create.sh +35 -0
  38. package/commonjs/src/webapi/devcontainer/templates/post-start.sh +65 -0
  39. package/commonjs/src/webapi/devcontainer/templates/tty-prompt.sh +38 -0
  40. package/commonjs/src/webapi/features/auth.feature.js +441 -0
  41. package/commonjs/src/webapi/features/auth0-cli.js +435 -0
  42. package/commonjs/src/webapi/features/biome-format.js +49 -0
  43. package/commonjs/src/webapi/features/database.feature.js +433 -0
  44. package/commonjs/src/webapi/features/finalize.feature.js +95 -0
  45. package/commonjs/src/webapi/features/postman.feature.js +324 -0
  46. package/commonjs/src/webapi/models/api-package-json.model.js +60 -0
  47. package/commonjs/src/webapi/models/auth-config.model.js +26 -0
  48. package/commonjs/src/webapi/models/controller-source-file.model.js +193 -0
  49. package/commonjs/src/webapi/models/github-ci.model.js +193 -0
  50. package/commonjs/src/webapi/models/main-source-file.model.js +167 -0
  51. package/commonjs/src/webapi/models/production-dockerfile.model.js +157 -0
  52. package/commonjs/src/webapi/models/sample-files.model.js +60 -0
  53. package/commonjs/src/webapi/models/webapi-image.model.js +27 -0
  54. package/commonjs/src/webapi/postman/hello-openapi.js +175 -0
  55. package/commonjs/src/webapi/postman/local-view.js +184 -0
  56. package/commonjs/src/webapi/postman/openapi-to-postman.js +202 -0
  57. package/commonjs/src/webapi/workspace-readme.js +110 -0
  58. package/commonjs/src/webapi.action.js +30 -0
  59. package/commonjs/src/webapi.command.js +45 -0
  60. package/es6/src/add-api.action.js +29 -0
  61. package/es6/src/add-api.command.js +31 -0
  62. package/es6/src/add.command.js +14 -0
  63. package/es6/src/add.module.js +16 -0
  64. package/es6/src/cli.js +5 -0
  65. package/es6/src/create.command.js +14 -0
  66. package/es6/src/create.module.js +16 -0
  67. package/es6/src/domain/prompt.js +43 -0
  68. package/es6/src/index.js +8 -0
  69. package/es6/src/models/compose.model.js +144 -0
  70. package/es6/src/models/config-yaml.model.js +76 -0
  71. package/es6/src/models/const.js +22 -0
  72. package/es6/src/models/dev-container.model.js +106 -0
  73. package/es6/src/models/docker-image.model.js +217 -0
  74. package/es6/src/models/env-file.model.js +46 -0
  75. package/es6/src/models/gitignore.model.js +33 -0
  76. package/es6/src/models/launch-json.model.js +64 -0
  77. package/es6/src/models/package-json.model.js +137 -0
  78. package/es6/src/models/project.model.js +119 -0
  79. package/es6/src/models/source-file.js +3 -0
  80. package/es6/src/models/tsconfig.model.js +24 -0
  81. package/es6/src/models/vitest-config.model.js +25 -0
  82. package/es6/src/models/vscode-settings.model.js +21 -0
  83. package/es6/src/program.js +39 -0
  84. package/es6/src/resolve-target-dir.js +9 -0
  85. package/es6/src/services/scaffold.service.js +52 -0
  86. package/es6/src/version.js +36 -0
  87. package/es6/src/webapi/api-name.js +59 -0
  88. package/es6/src/webapi/cli-options.js +36 -0
  89. package/es6/src/webapi/const.js +20 -0
  90. package/es6/src/webapi/create-api.js +217 -0
  91. package/es6/src/webapi/devcontainer/codebase-rag-mcp.js +156 -0
  92. package/es6/src/webapi/devcontainer/codebase-rag-mcp.ts +182 -0
  93. package/es6/src/webapi/devcontainer/host-scripts.js +31 -0
  94. package/es6/src/webapi/devcontainer/templates/codebase-rag.env.example +3 -0
  95. package/es6/src/webapi/devcontainer/templates/initialize.sh +169 -0
  96. package/es6/src/webapi/devcontainer/templates/post-create.sh +35 -0
  97. package/es6/src/webapi/devcontainer/templates/post-start.sh +65 -0
  98. package/es6/src/webapi/devcontainer/templates/tty-prompt.sh +38 -0
  99. package/es6/src/webapi/features/auth.feature.js +390 -0
  100. package/es6/src/webapi/features/auth0-cli.js +375 -0
  101. package/es6/src/webapi/features/biome-format.js +42 -0
  102. package/es6/src/webapi/features/database.feature.js +423 -0
  103. package/es6/src/webapi/features/finalize.feature.js +85 -0
  104. package/es6/src/webapi/features/postman.feature.js +258 -0
  105. package/es6/src/webapi/models/api-package-json.model.js +55 -0
  106. package/es6/src/webapi/models/auth-config.model.js +22 -0
  107. package/es6/src/webapi/models/controller-source-file.model.js +184 -0
  108. package/es6/src/webapi/models/github-ci.model.js +186 -0
  109. package/es6/src/webapi/models/main-source-file.model.js +163 -0
  110. package/es6/src/webapi/models/production-dockerfile.model.js +148 -0
  111. package/es6/src/webapi/models/sample-files.model.js +42 -0
  112. package/es6/src/webapi/models/webapi-image.model.js +20 -0
  113. package/es6/src/webapi/postman/hello-openapi.js +168 -0
  114. package/es6/src/webapi/postman/local-view.js +169 -0
  115. package/es6/src/webapi/postman/openapi-to-postman.js +179 -0
  116. package/es6/src/webapi/workspace-readme.js +89 -0
  117. package/es6/src/webapi.action.js +20 -0
  118. package/es6/src/webapi.command.js +35 -0
  119. package/package.json +8 -8
  120. package/types/src/add-api.action.d.ts +13 -0
  121. package/types/src/add-api.command.d.ts +7 -0
  122. package/types/src/add.command.d.ts +6 -0
  123. package/types/src/add.module.d.ts +14 -0
  124. package/types/src/cli.d.ts +2 -0
  125. package/types/src/create.command.d.ts +6 -0
  126. package/types/src/create.module.d.ts +14 -0
  127. package/types/src/domain/prompt.d.ts +4 -0
  128. package/types/src/models/compose.model.d.ts +64 -0
  129. package/types/src/models/config-yaml.model.d.ts +27 -0
  130. package/types/src/models/const.d.ts +20 -0
  131. package/types/src/models/dev-container.model.d.ts +37 -0
  132. package/types/src/models/docker-image.model.d.ts +84 -0
  133. package/types/src/models/env-file.model.d.ts +16 -0
  134. package/types/src/models/gitignore.model.d.ts +7 -0
  135. package/types/src/models/launch-json.model.d.ts +7 -0
  136. package/types/src/models/package-json.model.d.ts +35 -0
  137. package/types/src/models/project.model.d.ts +60 -0
  138. package/{src/models/source-file.ts → types/src/models/source-file.d.ts} +4 -6
  139. package/types/src/models/tsconfig.model.d.ts +5 -0
  140. package/types/src/models/vitest-config.model.d.ts +5 -0
  141. package/types/src/models/vscode-settings.model.d.ts +7 -0
  142. package/types/src/program.d.ts +3 -0
  143. package/{src/resolve-target-dir.ts → types/src/resolve-target-dir.d.ts} +1 -4
  144. package/types/src/services/scaffold.service.d.ts +22 -0
  145. package/types/src/version.d.ts +6 -0
  146. package/types/src/webapi/api-name.d.ts +14 -0
  147. package/types/src/webapi/cli-options.d.ts +6 -0
  148. package/{src/webapi/const.ts → types/src/webapi/const.d.ts} +7 -21
  149. package/types/src/webapi/create-api.d.ts +15 -0
  150. package/types/src/webapi/devcontainer/codebase-rag-mcp.d.ts +32 -0
  151. package/types/src/webapi/devcontainer/codebase-rag-mcp.ts +182 -0
  152. package/types/src/webapi/devcontainer/host-scripts.d.ts +7 -0
  153. package/types/src/webapi/devcontainer/templates/codebase-rag.env.example +3 -0
  154. package/types/src/webapi/devcontainer/templates/initialize.sh +169 -0
  155. package/types/src/webapi/devcontainer/templates/post-create.sh +35 -0
  156. package/types/src/webapi/devcontainer/templates/post-start.sh +65 -0
  157. package/types/src/webapi/devcontainer/templates/tty-prompt.sh +38 -0
  158. package/types/src/webapi/features/auth.feature.d.ts +10 -0
  159. package/types/src/webapi/features/auth0-cli.d.ts +80 -0
  160. package/types/src/webapi/features/biome-format.d.ts +5 -0
  161. package/types/src/webapi/features/database.feature.d.ts +7 -0
  162. package/types/src/webapi/features/finalize.feature.d.ts +2 -0
  163. package/types/src/webapi/features/postman.feature.d.ts +16 -0
  164. package/types/src/webapi/models/api-package-json.model.d.ts +18 -0
  165. package/types/src/webapi/models/auth-config.model.d.ts +26 -0
  166. package/types/src/webapi/models/controller-source-file.model.d.ts +46 -0
  167. package/types/src/webapi/models/github-ci.model.d.ts +9 -0
  168. package/types/src/webapi/models/main-source-file.model.d.ts +54 -0
  169. package/types/src/webapi/models/production-dockerfile.model.d.ts +23 -0
  170. package/types/src/webapi/models/sample-files.model.d.ts +7 -0
  171. package/types/src/webapi/models/webapi-image.model.d.ts +12 -0
  172. package/types/src/webapi/postman/hello-openapi.d.ts +19 -0
  173. package/types/src/webapi/postman/local-view.d.ts +17 -0
  174. package/types/src/webapi/postman/openapi-to-postman.d.ts +62 -0
  175. package/types/src/webapi/workspace-readme.d.ts +18 -0
  176. package/types/src/webapi.action.d.ts +14 -0
  177. package/types/src/webapi.command.d.ts +11 -0
  178. package/src/add-api.action.ts +0 -25
  179. package/src/add-api.command.ts +0 -31
  180. package/src/add.command.ts +0 -20
  181. package/src/add.module.ts +0 -11
  182. package/src/cli.ts +0 -4
  183. package/src/create.command.ts +0 -20
  184. package/src/create.module.ts +0 -11
  185. package/src/domain/prompt.ts +0 -50
  186. package/src/models/compose.model.ts +0 -205
  187. package/src/models/config-yaml.model.ts +0 -83
  188. package/src/models/const.ts +0 -20
  189. package/src/models/dev-container.model.ts +0 -136
  190. package/src/models/docker-image.model.ts +0 -343
  191. package/src/models/env-file.model.ts +0 -45
  192. package/src/models/gitignore.model.ts +0 -35
  193. package/src/models/launch-json.model.ts +0 -60
  194. package/src/models/package-json.model.ts +0 -169
  195. package/src/models/project.model.ts +0 -141
  196. package/src/models/tsconfig.model.ts +0 -29
  197. package/src/models/vitest-config.model.ts +0 -26
  198. package/src/models/vscode-settings.model.ts +0 -24
  199. package/src/program.ts +0 -63
  200. package/src/services/scaffold.service.ts +0 -89
  201. package/src/version.ts +0 -56
  202. package/src/webapi/api-name.ts +0 -73
  203. package/src/webapi/cli-options.ts +0 -56
  204. package/src/webapi/create-api.ts +0 -275
  205. package/src/webapi/devcontainer/host-scripts.ts +0 -35
  206. package/src/webapi/features/auth.feature.ts +0 -454
  207. package/src/webapi/features/auth0-cli.ts +0 -421
  208. package/src/webapi/features/biome-format.ts +0 -34
  209. package/src/webapi/features/database.feature.ts +0 -522
  210. package/src/webapi/features/finalize.feature.ts +0 -112
  211. package/src/webapi/features/postman.feature.ts +0 -287
  212. package/src/webapi/models/api-package-json.model.ts +0 -60
  213. package/src/webapi/models/auth-config.model.ts +0 -36
  214. package/src/webapi/models/controller-source-file.model.ts +0 -232
  215. package/src/webapi/models/github-ci.model.ts +0 -188
  216. package/src/webapi/models/main-source-file.model.ts +0 -208
  217. package/src/webapi/models/production-dockerfile.model.ts +0 -162
  218. package/src/webapi/models/sample-files.model.ts +0 -45
  219. package/src/webapi/models/webapi-image.model.ts +0 -21
  220. package/src/webapi/postman/hello-openapi.ts +0 -92
  221. package/src/webapi/postman/local-view.ts +0 -195
  222. package/src/webapi/postman/openapi-to-postman.ts +0 -208
  223. package/src/webapi/workspace-readme.ts +0 -192
  224. package/src/webapi.action.ts +0 -22
  225. package/src/webapi.command.ts +0 -41
  226. package/tests/auth-postman.wiring.spec.ts +0 -263
  227. package/tests/auth0-cli.spec.ts +0 -232
  228. package/tests/biome-format.spec.ts +0 -49
  229. package/tests/cli.integration.spec.ts +0 -658
  230. package/tests/compose.model.spec.ts +0 -51
  231. package/tests/container-image.model.spec.ts +0 -162
  232. package/tests/dev-container.model.spec.ts +0 -29
  233. package/tests/devcontainer-base-image.spec.ts +0 -32
  234. package/tests/hello-di-inject.scaffold.spec.ts +0 -18
  235. package/tests/hello-route.contract.spec.ts +0 -94
  236. package/tests/package-json.order.spec.ts +0 -59
  237. package/tests/postman-from-openapi.spec.ts +0 -197
  238. package/tests/seed-devcontainer-templates.ts +0 -40
  239. package/tests/webapi/devcontainer/codebase-rag-mcp.spec.ts +0 -96
  240. /package/{src/index.ts → types/src/index.d.ts} +0 -0
@@ -0,0 +1,182 @@
1
+ import {
2
+ chmodSync,
3
+ mkdirSync,
4
+ readFileSync,
5
+ renameSync,
6
+ statSync,
7
+ writeFileSync,
8
+ } from "node:fs";
9
+ import { dirname, join } from "node:path";
10
+ import { fileURLToPath } from "node:url";
11
+
12
+ export type CodebaseRagCredentials = {
13
+ url: string;
14
+ token: string;
15
+ };
16
+
17
+ export type McpJson = {
18
+ mcpServers?: Record<string, unknown>;
19
+ [key: string]: unknown;
20
+ };
21
+
22
+ function isRecord(value: unknown): value is Record<string, unknown> {
23
+ return value != null && typeof value === "object" && !Array.isArray(value);
24
+ }
25
+
26
+ function loadDotenv(path: string, env: NodeJS.ProcessEnv): void {
27
+ let raw: string;
28
+ try {
29
+ raw = readFileSync(path, "utf8");
30
+ } catch {
31
+ return;
32
+ }
33
+ for (const line of raw.split(/\r?\n/)) {
34
+ const trimmed = line.trim();
35
+ if (!trimmed || trimmed.startsWith("#") || !trimmed.includes("=")) continue;
36
+ const eq = trimmed.indexOf("=");
37
+ const key = trimmed.slice(0, eq).trim();
38
+ const value = trimmed
39
+ .slice(eq + 1)
40
+ .trim()
41
+ .replace(/^["']|["']$/g, "");
42
+ if (key && env[key] === undefined) env[key] = value;
43
+ }
44
+ }
45
+
46
+ function seedFromMcpJson(raw: string): CodebaseRagCredentials | null {
47
+ let data: unknown;
48
+ try {
49
+ data = JSON.parse(raw);
50
+ } catch {
51
+ return null;
52
+ }
53
+ if (!isRecord(data)) return null;
54
+ const servers = data.mcpServers;
55
+ if (!isRecord(servers)) return null;
56
+ const server = servers["codebase-rag"];
57
+ if (!isRecord(server)) return null;
58
+ const url = typeof server.url === "string" ? server.url.trim() : "";
59
+ const headers = isRecord(server.headers) ? server.headers : {};
60
+ const auth = typeof headers.Authorization === "string" ? headers.Authorization.trim() : "";
61
+ const token = auth.toLowerCase().startsWith("bearer ") ? auth.slice(7).trim() : "";
62
+ if (!url.startsWith("http") || token.length === 0) return null;
63
+ return { url, token };
64
+ }
65
+
66
+ function mergeIntoMcpJson(input: {
67
+ mcpPath: string;
68
+ url: string;
69
+ token: string;
70
+ hostRoot: string;
71
+ }): { skipped?: string; path?: string; root?: string } {
72
+ const { mcpPath, url, token, hostRoot } = input;
73
+ if (!url || !token) {
74
+ return { skipped: "no URL/token" };
75
+ }
76
+
77
+ const xRoot = hostRoot || "${workspaceFolder}";
78
+ mkdirSync(dirname(mcpPath), { recursive: true });
79
+
80
+ let data: McpJson = { mcpServers: {} };
81
+ try {
82
+ if (statSync(mcpPath).size > 0) {
83
+ const loaded: unknown = JSON.parse(readFileSync(mcpPath, "utf8"));
84
+ if (isRecord(loaded)) data = loaded as McpJson;
85
+ }
86
+ } catch (err) {
87
+ const code = isRecord(err) && typeof err.code === "string" ? err.code : "";
88
+ if (code !== "ENOENT") {
89
+ console.log(
90
+ "codebase-rag MCP: existing mcp.json is invalid JSON; replacing rag entry only after backup",
91
+ );
92
+ renameSync(mcpPath, `${mcpPath}.bak`);
93
+ }
94
+ }
95
+
96
+ const servers = isRecord(data.mcpServers) ? data.mcpServers : {};
97
+ data.mcpServers = servers;
98
+ servers["codebase-rag"] = {
99
+ url,
100
+ headers: {
101
+ Authorization: `Bearer ${token}`,
102
+ "X-Codebase-Root": xRoot,
103
+ },
104
+ };
105
+ writeFileSync(mcpPath, `${JSON.stringify(data, null, 2)}\n`, "utf8");
106
+ try {
107
+ chmodSync(mcpPath, 0o600);
108
+ } catch {
109
+ // memfs and some hosts omit chmod
110
+ }
111
+ return { path: mcpPath, root: xRoot };
112
+ }
113
+
114
+ function workspaceRoot(env: NodeJS.ProcessEnv = process.env): string {
115
+ const fromEnv = env.CODEBASE_RAG_WORKSPACE?.trim();
116
+ if (fromEnv) return fromEnv;
117
+ // Scaffolded copy lives at <repo>/.devcontainer/codebase-rag-mcp.ts
118
+ return dirname(dirname(fileURLToPath(import.meta.url)));
119
+ }
120
+
121
+ function mergeFromEnv(env: NodeJS.ProcessEnv = process.env): number {
122
+ const root = workspaceRoot(env);
123
+ const cursorDir = join(root, ".cursor");
124
+ loadDotenv(join(cursorDir, "codebase-rag.env"), env);
125
+ const url = (env.CODEBASE_RAG_MCP_URL ?? "").trim();
126
+ const token = (env.CODEBASE_RAG_MCP_TOKEN ?? "").trim();
127
+ const hostRoot = (env.CODEBASE_RAG_MCP_ROOT ?? "").trim() || root;
128
+ const result = mergeIntoMcpJson({
129
+ mcpPath: join(cursorDir, "mcp.json"),
130
+ url,
131
+ token,
132
+ hostRoot,
133
+ });
134
+ if (result.skipped != null) {
135
+ console.log(`codebase-rag MCP: skipped (${result.skipped})`);
136
+ return 0;
137
+ }
138
+ console.log(`codebase-rag MCP: wrote ${result.path} url=${url} root=${result.root}`);
139
+ return 0;
140
+ }
141
+
142
+ function seedPrint(mcpPath: string): number {
143
+ let raw: string;
144
+ try {
145
+ raw = readFileSync(mcpPath, "utf8");
146
+ } catch {
147
+ return 1;
148
+ }
149
+ const creds = seedFromMcpJson(raw);
150
+ if (creds == null) return 1;
151
+ console.log(creds.url);
152
+ console.log(creds.token);
153
+ return 0;
154
+ }
155
+
156
+ function main(argv = process.argv.slice(2)): number {
157
+ const command = argv[0] ?? "merge";
158
+ if (command === "seed-print") {
159
+ const mcpPath = argv[1];
160
+ if (mcpPath == null || mcpPath.length === 0) return 1;
161
+ return seedPrint(mcpPath);
162
+ }
163
+ if (command === "merge") {
164
+ return mergeFromEnv();
165
+ }
166
+ console.error(`codebase-rag MCP: unknown command ${command}`);
167
+ return 1;
168
+ }
169
+
170
+ const invoked = (process.argv[1] ?? "").replaceAll("\\", "/");
171
+ if (invoked.endsWith("/codebase-rag-mcp.ts") || invoked.endsWith("/codebase-rag-mcp.js")) {
172
+ process.exit(main());
173
+ }
174
+
175
+ export const codebaseRagMcp = {
176
+ loadDotenv,
177
+ seedFromMcpJson,
178
+ mergeIntoMcpJson,
179
+ mergeFromEnv,
180
+ seedPrint,
181
+ main,
182
+ };
@@ -0,0 +1,31 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { fileURLToPath } from "node:url";
3
+ const TEMPLATE_FILES = [
4
+ "initialize.sh",
5
+ "post-create.sh",
6
+ "post-start.sh",
7
+ "tty-prompt.sh",
8
+ "codebase-rag.env.example"
9
+ ];
10
+ export function devcontainerTemplatePath(name) {
11
+ return fileURLToPath(new URL(`./templates/${name}`, import.meta.url));
12
+ }
13
+ export function codebaseRagMcpSourcePath() {
14
+ return fileURLToPath(new URL("./codebase-rag-mcp.ts", import.meta.url));
15
+ }
16
+ /** Host + container scripts for the scaffolded Dev Container. */ export class DevContainerHostScripts {
17
+ files() {
18
+ return [
19
+ ...TEMPLATE_FILES.map((name)=>({
20
+ filePath: `.devcontainer/${name}`,
21
+ content: readFileSync(devcontainerTemplatePath(name), "utf8")
22
+ })),
23
+ {
24
+ filePath: ".devcontainer/codebase-rag-mcp.ts",
25
+ content: readFileSync(codebaseRagMcpSourcePath(), "utf8")
26
+ }
27
+ ];
28
+ }
29
+ }
30
+
31
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi9ob21lL3J1bm5lci93b3JrL2RlY29oZXJlL2RlY29oZXJlL3Byb2plY3RzL3NjYWZmb2xkL3NyYy93ZWJhcGkvZGV2Y29udGFpbmVyL2hvc3Qtc2NyaXB0cy50cyJdLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyByZWFkRmlsZVN5bmMgfSBmcm9tIFwibm9kZTpmc1wiO1xuaW1wb3J0IHsgZmlsZVVSTFRvUGF0aCB9IGZyb20gXCJub2RlOnVybFwiO1xuaW1wb3J0IHR5cGUgeyBTb3VyY2VGaWxlLCBTb3VyY2VGaWxlUHJvdmlkZXIgfSBmcm9tIFwiLi4vLi4vbW9kZWxzL3NvdXJjZS1maWxlLmpzXCI7XG5cbmNvbnN0IFRFTVBMQVRFX0ZJTEVTID0gW1xuXHRcImluaXRpYWxpemUuc2hcIixcblx0XCJwb3N0LWNyZWF0ZS5zaFwiLFxuXHRcInBvc3Qtc3RhcnQuc2hcIixcblx0XCJ0dHktcHJvbXB0LnNoXCIsXG5cdFwiY29kZWJhc2UtcmFnLmVudi5leGFtcGxlXCIsXG5dIGFzIGNvbnN0O1xuXG5leHBvcnQgZnVuY3Rpb24gZGV2Y29udGFpbmVyVGVtcGxhdGVQYXRoKG5hbWU6IHN0cmluZyk6IHN0cmluZyB7XG5cdHJldHVybiBmaWxlVVJMVG9QYXRoKG5ldyBVUkwoYC4vdGVtcGxhdGVzLyR7bmFtZX1gLCBpbXBvcnQubWV0YS51cmwpKTtcbn1cblxuZXhwb3J0IGZ1bmN0aW9uIGNvZGViYXNlUmFnTWNwU291cmNlUGF0aCgpOiBzdHJpbmcge1xuXHRyZXR1cm4gZmlsZVVSTFRvUGF0aChuZXcgVVJMKFwiLi9jb2RlYmFzZS1yYWctbWNwLnRzXCIsIGltcG9ydC5tZXRhLnVybCkpO1xufVxuXG4vKiogSG9zdCArIGNvbnRhaW5lciBzY3JpcHRzIGZvciB0aGUgc2NhZmZvbGRlZCBEZXYgQ29udGFpbmVyLiAqL1xuZXhwb3J0IGNsYXNzIERldkNvbnRhaW5lckhvc3RTY3JpcHRzIGltcGxlbWVudHMgU291cmNlRmlsZVByb3ZpZGVyIHtcblx0cHVibGljIGZpbGVzKCk6IFNvdXJjZUZpbGVbXSB7XG5cdFx0cmV0dXJuIFtcblx0XHRcdC4uLlRFTVBMQVRFX0ZJTEVTLm1hcCgobmFtZSkgPT4gKHtcblx0XHRcdFx0ZmlsZVBhdGg6IGAuZGV2Y29udGFpbmVyLyR7bmFtZX1gLFxuXHRcdFx0XHRjb250ZW50OiByZWFkRmlsZVN5bmMoZGV2Y29udGFpbmVyVGVtcGxhdGVQYXRoKG5hbWUpLCBcInV0ZjhcIiksXG5cdFx0XHR9KSksXG5cdFx0XHR7XG5cdFx0XHRcdGZpbGVQYXRoOiBcIi5kZXZjb250YWluZXIvY29kZWJhc2UtcmFnLW1jcC50c1wiLFxuXHRcdFx0XHRjb250ZW50OiByZWFkRmlsZVN5bmMoY29kZWJhc2VSYWdNY3BTb3VyY2VQYXRoKCksIFwidXRmOFwiKSxcblx0XHRcdH0sXG5cdFx0XTtcblx0fVxufVxuIl0sIm5hbWVzIjpbInJlYWRGaWxlU3luYyIsImZpbGVVUkxUb1BhdGgiLCJURU1QTEFURV9GSUxFUyIsImRldmNvbnRhaW5lclRlbXBsYXRlUGF0aCIsIm5hbWUiLCJVUkwiLCJ1cmwiLCJjb2RlYmFzZVJhZ01jcFNvdXJjZVBhdGgiLCJEZXZDb250YWluZXJIb3N0U2NyaXB0cyIsImZpbGVzIiwibWFwIiwiZmlsZVBhdGgiLCJjb250ZW50Il0sIm1hcHBpbmdzIjoiQUFBQSxTQUFTQSxZQUFZLFFBQVEsVUFBVTtBQUN2QyxTQUFTQyxhQUFhLFFBQVEsV0FBVztBQUd6QyxNQUFNQyxpQkFBaUI7SUFDdEI7SUFDQTtJQUNBO0lBQ0E7SUFDQTtDQUNBO0FBRUQsT0FBTyxTQUFTQyx5QkFBeUJDLElBQVk7SUFDcEQsT0FBT0gsY0FBYyxJQUFJSSxJQUFJLENBQUMsWUFBWSxFQUFFRCxNQUFNLEVBQUUsWUFBWUUsR0FBRztBQUNwRTtBQUVBLE9BQU8sU0FBU0M7SUFDZixPQUFPTixjQUFjLElBQUlJLElBQUkseUJBQXlCLFlBQVlDLEdBQUc7QUFDdEU7QUFFQSwrREFBK0QsR0FDL0QsT0FBTyxNQUFNRTtJQUNMQyxRQUFzQjtRQUM1QixPQUFPO2VBQ0hQLGVBQWVRLEdBQUcsQ0FBQyxDQUFDTixPQUFVLENBQUE7b0JBQ2hDTyxVQUFVLENBQUMsY0FBYyxFQUFFUCxNQUFNO29CQUNqQ1EsU0FBU1osYUFBYUcseUJBQXlCQyxPQUFPO2dCQUN2RCxDQUFBO1lBQ0E7Z0JBQ0NPLFVBQVU7Z0JBQ1ZDLFNBQVNaLGFBQWFPLDRCQUE0QjtZQUNuRDtTQUNBO0lBQ0Y7QUFDRCJ9
@@ -0,0 +1,3 @@
1
+ # Optional. Written to .cursor/codebase-rag.env by initialize.sh (gitignored).
2
+ # CODEBASE_RAG_MCP_URL=https://rag.example.com/mcp
3
+ # CODEBASE_RAG_MCP_TOKEN=
@@ -0,0 +1,169 @@
1
+ #!/usr/bin/env bash
2
+ # Runs on the host before the container is created (devcontainer initializeCommand).
3
+ # Creates bind-mount sources as the host user so Docker does not create them as root.
4
+ # Optional npm / gh / MCP setup is y/N on a TTY; no TTY skips.
5
+ set -euo pipefail
6
+
7
+ root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
8
+ here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9
+ # shellcheck source=tty-prompt.sh
10
+ source "$here/tty-prompt.sh"
11
+
12
+ npm_dir="$root/.devcontainer/npm-auth"
13
+ gh_dir="$root/.devcontainer/gh-auth"
14
+ gh_env="$root/.devcontainer/gh.env"
15
+ cursor_dir="$root/.cursor"
16
+ RAG_ENV="$cursor_dir/codebase-rag.env"
17
+
18
+ run_codebase_rag_mcp() {
19
+ local script="$here/codebase-rag-mcp.ts"
20
+ CODEBASE_RAG_WORKSPACE="$root" node --experimental-strip-types "$script" "$@"
21
+ }
22
+
23
+ load_rag_env() {
24
+ RAG_URL=""
25
+ RAG_TOKEN=""
26
+ [[ -f "$RAG_ENV" ]] || return 0
27
+ # shellcheck disable=SC1090
28
+ set -a
29
+ # shellcheck disable=SC1090
30
+ source "$RAG_ENV"
31
+ set +a
32
+ RAG_URL="${CODEBASE_RAG_MCP_URL:-}"
33
+ RAG_TOKEN="${CODEBASE_RAG_MCP_TOKEN:-}"
34
+ }
35
+
36
+ write_rag_env() {
37
+ mkdir -p "$(dirname "$RAG_ENV")"
38
+ umask 077
39
+ cat >"$RAG_ENV" <<EOF
40
+ # Written by .devcontainer/initialize.sh. Not in git.
41
+ CODEBASE_RAG_MCP_URL=${RAG_URL}
42
+ CODEBASE_RAG_MCP_TOKEN=${RAG_TOKEN}
43
+ CODEBASE_RAG_MCP_ROOT=${root}
44
+ EOF
45
+ chmod 600 "$RAG_ENV"
46
+ if [[ -n "$RAG_URL" && -n "$RAG_TOKEN" ]]; then
47
+ run_codebase_rag_mcp merge || true
48
+ fi
49
+ }
50
+
51
+ seed_rag_from_host_mcp() {
52
+ local mcp="${HOME}/.cursor/mcp.json"
53
+ [[ -f "$mcp" ]] || return 1
54
+ command -v node >/dev/null 2>&1 || return 1
55
+ run_codebase_rag_mcp seed-print "$mcp"
56
+ }
57
+
58
+ ensure_cursor_dir() {
59
+ mkdir -p "$cursor_dir"
60
+ }
61
+
62
+ ensure_auth_dir() {
63
+ local dir="$1"
64
+ if ! mkdir -p "$dir" 2>/dev/null; then
65
+ echo "Cannot create $dir (permission denied)." >&2
66
+ echo "The scaffold container likely left .devcontainer root-owned. Fix with:" >&2
67
+ echo " sudo chown -R \"$USER:$USER\" \"$root\"" >&2
68
+ exit 1
69
+ fi
70
+ {
71
+ echo "*"
72
+ echo "!.gitignore"
73
+ } >"$dir/.gitignore"
74
+ }
75
+
76
+ ensure_gh_env() {
77
+ if [[ -d "$gh_env" ]]; then
78
+ echo "Refusing to start: $gh_env is a directory (left by a prior bind mount). Remove it and rebuild." >&2
79
+ exit 1
80
+ fi
81
+ touch "$gh_env"
82
+ }
83
+
84
+ setup_npm_auth() {
85
+ if [[ -f "$npm_dir/.npmrc" ]]; then
86
+ echo "npm auth: using $npm_dir/.npmrc"
87
+ return 0
88
+ fi
89
+ if ! prompt_yn "Configure npm auth for this workspace?"; then
90
+ echo "npm auth: skipped"
91
+ return 0
92
+ fi
93
+ if [[ -f "${HOME}/.npmrc" ]]; then
94
+ cp -a "${HOME}/.npmrc" "$npm_dir/.npmrc"
95
+ echo "npm auth: copied ~/.npmrc → $npm_dir/.npmrc"
96
+ return 0
97
+ fi
98
+ echo "npm auth: no ~/.npmrc — log in inside the container if prompted"
99
+ }
100
+
101
+ setup_gh_auth() {
102
+ if [[ -f "$gh_dir/hosts.yml" ]]; then
103
+ echo "gh auth: using $gh_dir/hosts.yml"
104
+ return 0
105
+ fi
106
+ if ! prompt_yn "Configure GitHub CLI auth for this workspace?"; then
107
+ echo "gh auth: skipped"
108
+ return 0
109
+ fi
110
+ if [[ -f "${HOME}/.config/gh/hosts.yml" ]]; then
111
+ cp -a "${HOME}/.config/gh/hosts.yml" "$gh_dir/hosts.yml"
112
+ [[ -f "${HOME}/.config/gh/config.yml" ]] &&
113
+ cp -a "${HOME}/.config/gh/config.yml" "$gh_dir/config.yml"
114
+ echo "gh auth: copied ~/.config/gh → $gh_dir"
115
+ return 0
116
+ fi
117
+ echo "gh auth: no ~/.config/gh/hosts.yml — log in inside the container if prompted"
118
+ }
119
+
120
+ setup_codebase_rag_env() {
121
+ load_rag_env
122
+ if [[ -n "$RAG_URL" && -n "$RAG_TOKEN" ]]; then
123
+ write_rag_env
124
+ echo "codebase-rag MCP: using $RAG_ENV"
125
+ return 0
126
+ fi
127
+
128
+ local seeded
129
+ if seeded="$(seed_rag_from_host_mcp 2>/dev/null)"; then
130
+ if prompt_yn "Found codebase-rag in ~/.cursor/mcp.json. Use it for this workspace?" y; then
131
+ RAG_URL="$(printf '%s\n' "$seeded" | sed -n '1p')"
132
+ RAG_TOKEN="$(printf '%s\n' "$seeded" | sed -n '2p')"
133
+ write_rag_env
134
+ echo "codebase-rag MCP: imported HTTP server from ~/.cursor/mcp.json → $RAG_ENV"
135
+ return 0
136
+ fi
137
+ fi
138
+
139
+ if ! prompt_yn "Configure codebase RAG MCP (semantic search)?"; then
140
+ RAG_URL=""
141
+ RAG_TOKEN=""
142
+ write_rag_env
143
+ echo "codebase-rag MCP: skipped"
144
+ return 0
145
+ fi
146
+
147
+ printf '%s\n' "Empty URL skips. Example: https://rag.example.com/mcp" >/dev/tty
148
+ printf '%s' "MCP URL: " >/dev/tty
149
+ read_tty RAG_URL
150
+ RAG_URL="$(printf '%s' "$RAG_URL" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
151
+ if [[ -z "$RAG_URL" ]]; then
152
+ RAG_TOKEN=""
153
+ write_rag_env
154
+ echo "codebase-rag MCP: skipped"
155
+ return 0
156
+ fi
157
+ printf '%s' "Bearer token (hidden): " >/dev/tty
158
+ read_tty RAG_TOKEN hidden
159
+ write_rag_env
160
+ echo "codebase-rag MCP: saved $RAG_ENV"
161
+ }
162
+
163
+ ensure_auth_dir "$npm_dir"
164
+ ensure_auth_dir "$gh_dir"
165
+ ensure_gh_env
166
+ ensure_cursor_dir
167
+ setup_npm_auth
168
+ setup_gh_auth
169
+ setup_codebase_rag_env
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env bash
2
+ # Runs after container create and when workspace content updates
3
+ # (devcontainer postCreateCommand / updateContentCommand).
4
+ # Installs deps when missing or when the lockfile changed; skips otherwise.
5
+ set -euo pipefail
6
+
7
+ root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
8
+ cd "$root"
9
+
10
+ lockfile="pnpm-lock.yaml"
11
+ stamp="node_modules/.decohere-pnpm-lock.sha"
12
+
13
+ current_hash=""
14
+ if [[ -f "$lockfile" ]]; then
15
+ current_hash="$(sha256sum "$lockfile" | awk '{print $1}')"
16
+ elif [[ -f package.json ]]; then
17
+ current_hash="$(sha256sum package.json | awk '{print $1}')"
18
+ fi
19
+
20
+ if [[ -d node_modules/.bin ]] && [[ -n "$current_hash" ]] && [[ -f "$stamp" ]] && [[ "$(cat "$stamp")" == "$current_hash" ]]; then
21
+ echo "node_modules: up to date, skipping pnpm install"
22
+ exit 0
23
+ fi
24
+
25
+ echo "node_modules: installing dependencies (first create may take a while)..."
26
+ if [[ -f "$lockfile" ]]; then
27
+ pnpm install --frozen-lockfile
28
+ else
29
+ pnpm install
30
+ fi
31
+
32
+ if [[ -n "$current_hash" ]]; then
33
+ mkdir -p node_modules
34
+ printf '%s\n' "$current_hash" >"$stamp"
35
+ fi
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env bash
2
+ # Runs on every container start (devcontainer postStartCommand).
3
+ # Optional npm / gh login is y/N on a TTY. Install is post-create.sh.
4
+ # MCP merge also runs here for later reconnects; the Compose service command
5
+ # merges before Cursor attaches (postStart is too late for the first snapshot).
6
+ set -euo pipefail
7
+
8
+ here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9
+ root="$(cd "$here/.." && pwd)"
10
+ # shellcheck source=tty-prompt.sh
11
+ source "$here/tty-prompt.sh"
12
+
13
+ CODEBASE_RAG_WORKSPACE="$root" node --experimental-strip-types "$here/codebase-rag-mcp.ts" merge ||
14
+ echo "codebase-rag MCP: merge skipped" >&2
15
+
16
+ AUTH_REGISTRY="https://registry.npmjs.org"
17
+
18
+ ensure_npm_auth() {
19
+ if npm whoami --registry "$AUTH_REGISTRY" >/dev/null 2>&1; then
20
+ echo "npm: logged in as $(npm whoami --registry "$AUTH_REGISTRY")"
21
+ return 0
22
+ fi
23
+
24
+ if prompt_yn "Log in to npm?"; then
25
+ echo "npm: starting login..."
26
+ npm login --registry "$AUTH_REGISTRY" </dev/tty >/dev/tty
27
+ return 0
28
+ fi
29
+
30
+ echo "npm: skipped. Open a terminal and run: npm login" >&2
31
+ echo " (creds persist in .devcontainer/npm-auth/)" >&2
32
+ return 1
33
+ }
34
+
35
+ ensure_gh_auth() {
36
+ if ! command -v gh >/dev/null 2>&1; then
37
+ echo "gh: not installed in this container" >&2
38
+ return 1
39
+ fi
40
+
41
+ if gh auth status >/dev/null 2>&1; then
42
+ echo "gh: $(gh auth status 2>&1 | head -n1)"
43
+ return 0
44
+ fi
45
+
46
+ local token="${GH_TOKEN:-${GITHUB_TOKEN:-}}"
47
+ if [[ -n "$token" ]]; then
48
+ echo "gh: authenticating from GH_TOKEN..."
49
+ printf '%s\n' "$token" | gh auth login --with-token
50
+ return 0
51
+ fi
52
+
53
+ if prompt_yn "Log in to GitHub CLI (gh)?"; then
54
+ echo "gh: starting login..."
55
+ gh auth login </dev/tty >/dev/tty
56
+ return 0
57
+ fi
58
+
59
+ echo "gh: skipped. Open a terminal and run: gh auth login" >&2
60
+ echo " (creds persist in .devcontainer/gh-auth/; or set GH_TOKEN in .devcontainer/gh.env)" >&2
61
+ return 1
62
+ }
63
+
64
+ ensure_npm_auth || true
65
+ ensure_gh_auth || true
@@ -0,0 +1,38 @@
1
+ can_prompt() {
2
+ [[ -r /dev/tty && -w /dev/tty ]]
3
+ }
4
+
5
+ read_tty() {
6
+ local var="$1"
7
+ local hidden="${2:-}"
8
+ local value=""
9
+ if [[ -n "$hidden" ]]; then
10
+ read -r -s value </dev/tty || true
11
+ printf '\n' >/dev/tty
12
+ else
13
+ read -r value </dev/tty || true
14
+ fi
15
+ printf -v "$var" '%s' "$value"
16
+ }
17
+
18
+ # Returns 0 for yes. Default is n unless the second argument is y.
19
+ prompt_yn() {
20
+ local question="$1"
21
+ local default="${2:-n}"
22
+ local reply=""
23
+ if ! can_prompt; then
24
+ return 1
25
+ fi
26
+ local hint="y/N"
27
+ if [[ "$default" == "y" ]]; then
28
+ hint="Y/n"
29
+ fi
30
+ printf '%s [%s] ' "$question" "$hint" >/dev/tty
31
+ read_tty reply
32
+ reply="$(printf '%s' "$reply" | tr '[:upper:]' '[:lower:]' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
33
+ if [[ -z "$reply" ]]; then
34
+ [[ "$default" == "y" ]]
35
+ return
36
+ fi
37
+ [[ "$reply" == "y" || "$reply" == "yes" ]]
38
+ }