sponson 0.0.0-stage → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +10 -2
  3. package/dist/bin.d.ts +2 -0
  4. package/dist/bin.js +4 -0
  5. package/dist/bin.js.map +1 -0
  6. package/dist/commands/apply.d.ts +25 -0
  7. package/dist/commands/apply.js +55 -0
  8. package/dist/commands/apply.js.map +1 -0
  9. package/dist/commands/init.d.ts +70 -0
  10. package/dist/commands/init.js +223 -0
  11. package/dist/commands/init.js.map +1 -0
  12. package/dist/commands/mcp.d.ts +33 -0
  13. package/dist/commands/mcp.js +187 -0
  14. package/dist/commands/mcp.js.map +1 -0
  15. package/dist/commands/plan.d.ts +10 -0
  16. package/dist/commands/plan.js +23 -0
  17. package/dist/commands/plan.js.map +1 -0
  18. package/dist/context.d.ts +63 -0
  19. package/dist/context.js +105 -0
  20. package/dist/context.js.map +1 -0
  21. package/dist/detect.d.ts +72 -0
  22. package/dist/detect.js +228 -0
  23. package/dist/detect.js.map +1 -0
  24. package/dist/index.d.ts +8 -0
  25. package/dist/index.js +8 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/main.d.ts +29 -0
  28. package/dist/main.js +134 -0
  29. package/dist/main.js.map +1 -0
  30. package/dist/output.d.ts +24 -0
  31. package/dist/output.js +53 -0
  32. package/dist/output.js.map +1 -0
  33. package/dist/registry.d.ts +18 -0
  34. package/dist/registry.js +54 -0
  35. package/dist/registry.js.map +1 -0
  36. package/dist/render.d.ts +47 -0
  37. package/dist/render.js +231 -0
  38. package/dist/render.js.map +1 -0
  39. package/dist/stack.d.ts +113 -0
  40. package/dist/stack.js +341 -0
  41. package/dist/stack.js.map +1 -0
  42. package/dist/starter.d.ts +26 -0
  43. package/dist/starter.js +445 -0
  44. package/dist/starter.js.map +1 -0
  45. package/dist/version.d.ts +2 -0
  46. package/dist/version.js +4 -0
  47. package/dist/version.js.map +1 -0
  48. package/package.json +63 -3
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,11 @@
1
- # Temporary Holding Version
1
+ # sponson
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The Sponson CLI and MCP server: `sponson plan`, `sponson apply`, `sponson init` and `sponson mcp` read `release.plan.yaml` and plan, apply or destroy everything that ships beside the code (database branches, env vars, auth redirects) for one environment and scope.
4
+
5
+ ```sh
6
+ npx sponson plan
7
+ ```
8
+
9
+ Requires Node.js 22 or later.
10
+
11
+ Documentation: <https://sponson.mintlify.site> (quickstart, plan format, GitHub Action, agents). Source and issues: [GitHub](https://github.com/MishaBear94/Sponson).
package/dist/bin.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/bin.js ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { run } from "./main.js";
3
+ process.exitCode = await run(process.argv.slice(2));
4
+ //# sourceMappingURL=bin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEhC,OAAO,CAAC,QAAQ,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { type ApplyResultSummary, type Redactor } from "@sponson/core";
2
+ import { type GlobalOpts, type IO } from "../context.js";
3
+ export interface ApplyOpts extends GlobalOpts {
4
+ destroy?: boolean;
5
+ approvedBy?: string;
6
+ reconcile?: boolean;
7
+ /** Line ids, or a comma-separated string of them (MCP). */
8
+ recreate?: string[] | string;
9
+ /** Manual steps a person did (ADR 0021): line ids, or a comma-separated string of them (MCP). */
10
+ confirm?: string[] | string;
11
+ wait?: boolean;
12
+ /** Seconds. */
13
+ waitTimeout?: string | number;
14
+ }
15
+ export interface ApplyOutcome {
16
+ summary: ApplyResultSummary;
17
+ /**
18
+ * 0 for complete and partial (waiting on a deploy is not a failure), 1 for failed, and MANUAL_STEP_PENDING's exit
19
+ * code (2) when a manual step waits for a person: that is not done until someone does it.
20
+ */
21
+ code: number;
22
+ }
23
+ /** Shared by the CLI and the MCP server. */
24
+ export declare function executeApply(opts: ApplyOpts, io: IO, redactor: Redactor): Promise<ApplyOutcome>;
25
+ export declare function applyCommand(opts: ApplyOpts, io: IO, redactor: Redactor): Promise<number>;
@@ -0,0 +1,55 @@
1
+ import { applyRun, destroyRun, exitCodeFor } from "@sponson/core";
2
+ import { UsageError, gitUser, resolveApprover, toRunOptions, withInvocation } from "../context.js";
3
+ import { withRedactorWarnings } from "../output.js";
4
+ import { applyJson, renderApply } from "../render.js";
5
+ /** Shared by the CLI and the MCP server. */
6
+ export async function executeApply(opts, io, redactor) {
7
+ const waitTimeoutMs = parseTimeout(opts.waitTimeout);
8
+ return withInvocation(opts, io, redactor, async (inv) => {
9
+ const approvedBy = resolveApprover(opts.approvedBy, io.env);
10
+ const confirm = recreateList(opts.confirm);
11
+ const run = toRunOptions(inv, io, {
12
+ approvedBy,
13
+ reconcile: opts.reconcile,
14
+ recreate: recreateList(opts.recreate),
15
+ ...(confirm ? { confirm, confirmedBy: await confirmer(approvedBy, io.cwd) } : {}),
16
+ wait: opts.wait,
17
+ waitTimeoutMs,
18
+ });
19
+ const summary = opts.destroy ? await destroyRun(run) : await applyRun(run);
20
+ summary.warnings = withRedactorWarnings([...inv.warnings, ...summary.warnings], redactor);
21
+ const code = summary.receipt.status === "failed" ? 1 : summary.manual?.length ? exitCodeFor("MANUAL_STEP_PENDING") : 0;
22
+ return { summary, code };
23
+ });
24
+ }
25
+ export async function applyCommand(opts, io, redactor) {
26
+ const { summary, code } = await executeApply(opts, io, redactor);
27
+ if (opts.json)
28
+ io.json(applyJson(summary, code));
29
+ else
30
+ io.stdout.write(renderApply(summary, { color: io.color }));
31
+ return code;
32
+ }
33
+ function parseTimeout(raw) {
34
+ if (raw === undefined)
35
+ return undefined;
36
+ const n = Number(raw);
37
+ if (typeof raw === "string" && raw.trim() === "")
38
+ throw new UsageError("--wait-timeout must be a positive number of seconds (got \"\")");
39
+ if (!Number.isFinite(n) || n <= 0)
40
+ throw new UsageError(`--wait-timeout must be a positive number of seconds (got ${JSON.stringify(raw)})`);
41
+ return n * 1000;
42
+ }
43
+ /** Who confirms a manual step: the approver when one is given, else the git user. */
44
+ async function confirmer(approvedBy, cwd) {
45
+ const who = approvedBy ?? (await gitUser(cwd));
46
+ if (!who)
47
+ throw new UsageError("--confirm records who did the step: pass --approved-by <who> (or set SPONSON_APPROVED_BY), or configure git user.name / user.email");
48
+ return who;
49
+ }
50
+ /** Line ids from a repeatable flag, or from a comma-separated string (MCP). */
51
+ function recreateList(raw) {
52
+ const ids = (typeof raw === "string" ? raw.split(",") : (raw ?? [])).map((v) => v.trim()).filter(Boolean);
53
+ return ids.length ? ids : undefined;
54
+ }
55
+ //# sourceMappingURL=apply.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply.js","sourceRoot":"","sources":["../../src/commands/apply.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAA0C,MAAM,eAAe,CAAC;AAC1G,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,cAAc,EAA4B,MAAM,eAAe,CAAC;AAC7H,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAwBtD,4CAA4C;AAC5C,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,IAAe,EAAE,EAAM,EAAE,QAAkB;IAC5E,MAAM,aAAa,GAAG,YAA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;AAED,+EAA+E;AAC/E,SAAS,YAAY,CAAC,GAAkC;IACtD,MAAM,GAAG,GAAG,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC1G,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;AACtC,CAAC"}
@@ -0,0 +1,70 @@
1
+ import { type Ctx, type Drift, type Redactor, type Registry } from "@sponson/core";
2
+ import { type GlobalOpts, type IO } from "../context.js";
3
+ import { type Finding, type UnsupportedFinding } from "../stack.js";
4
+ import { type Todo } from "../starter.js";
5
+ export interface InitOpts extends GlobalOpts {
6
+ /** Adopt only the unmanaged resource whose key, id or label matches. */
7
+ adopt?: string;
8
+ }
9
+ export interface InitDetected {
10
+ /** What Sponson can use: providers (first-class adapters and recipe providers, see docs/providers.md), frameworks and ORMs, each with its evidence. */
11
+ found: Finding[];
12
+ /** Detected but not managed by any built-in adapter or recipe yet, each with a pointer to an issue. */
13
+ unsupported: UnsupportedFinding[];
14
+ /** Placeholders left in the plan, with where to find the real value. */
15
+ todo: Todo[];
16
+ /** True when no deploy target or database Sponson manages was detected and the plan starts from the Vercel + Neon template. */
17
+ assumed: boolean;
18
+ }
19
+ export interface InitResult {
20
+ ok: true;
21
+ command: "init";
22
+ /** True when the plan file did not exist and a starter was written. */
23
+ created: boolean;
24
+ path: string;
25
+ /**
26
+ * What the repository's files say it uses, when a starter was written; `null` when the plan already existed.
27
+ * File, dependency and variable names only: never a value read from an `.env` file.
28
+ */
29
+ detected: InitDetected | null;
30
+ /** Lines appended to an existing plan, with the resource keys each one adopts. */
31
+ added: Array<{
32
+ id: string;
33
+ adapter: string;
34
+ op: string;
35
+ keys: string[];
36
+ }>;
37
+ warnings: string[];
38
+ }
39
+ /**
40
+ * `init` always makes the plan catch up with reality: it writes a starter plan when there is none,
41
+ * and adopts unmanaged resources into an existing one. It never writes values, only references,
42
+ * and never reformats what is already in the file.
43
+ */
44
+ export declare function initCommand(opts: InitOpts, io: IO, redactor: Redactor): Promise<number>;
45
+ /** The short human summary: what was found, what is not supported yet, what is left to fill in, what to run next. */
46
+ export declare function initSummary(d: InitDetected, credentials: string[]): string[];
47
+ type ChangeDoc = Record<string, unknown> & {
48
+ id: string;
49
+ };
50
+ export interface Adoption {
51
+ change: ChangeDoc;
52
+ /** Resource keys this line adopts. */
53
+ keys: string[];
54
+ }
55
+ /**
56
+ * Turn unmanaged drift into plan lines. What a line looks like is provider knowledge, so each op that listed
57
+ * the resources builds its own lines (`OpSpec.adopt`); this only groups, makes ids unique and scopes the lines
58
+ * to the current environment. Resources whose op cannot adopt are reported as warnings, never guessed at.
59
+ */
60
+ export declare function adoptChanges(unmanaged: Drift[], registry: Registry, ctx: Ctx, takenIds: string[]): {
61
+ adoptions: Adoption[];
62
+ warnings: string[];
63
+ };
64
+ /**
65
+ * Append lines to `changes:` as text. Each new line is rendered on its own and spliced in after the last
66
+ * existing line of the list, so every byte already in the file (comments, quoting, flow maps, blank lines)
67
+ * stays exactly as it was.
68
+ */
69
+ export declare function appendChanges(source: string, changes: ChangeDoc[]): string;
70
+ export {};
@@ -0,0 +1,223 @@
1
+ import { readFile, writeFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { GitBranchReceiptStore, isKeepRef, planRun, walkParams } from "@sponson/core";
4
+ import { Document, isMap, isScalar, isSeq, parseDocument, visit } from "yaml";
5
+ import { UsageError, planPathFor, toRunOptions, withInvocation } from "../context.js";
6
+ import { withRedactorWarnings } from "../output.js";
7
+ import { detectStack, fsReader } from "../stack.js";
8
+ import { composeStarter, credentialsFor } from "../starter.js";
9
+ /**
10
+ * `init` always makes the plan catch up with reality: it writes a starter plan when there is none,
11
+ * and adopts unmanaged resources into an existing one. It never writes values, only references,
12
+ * and never reformats what is already in the file.
13
+ */
14
+ export async function initCommand(opts, io, redactor) {
15
+ const planPath = planPathFor(opts, io);
16
+ const existing = await readFile(planPath, "utf8").catch(() => null);
17
+ const result = { ok: true, command: "init", created: false, path: planPath, detected: null, added: [], warnings: [] };
18
+ const text = [];
19
+ if (existing === null) {
20
+ const starter = await writeStarter(planPath, io);
21
+ result.created = true;
22
+ result.detected = starter.detected;
23
+ text.push(...starter.text);
24
+ }
25
+ else {
26
+ text.push(...(await withInvocation(opts, io, redactor, (inv) => adoptUnmanaged(inv, existing, opts, io, result))));
27
+ result.warnings = withRedactorWarnings(result.warnings, redactor);
28
+ }
29
+ if (await ensureGitignore(io.cwd))
30
+ text.push("Added .sponson/ to .gitignore");
31
+ if (opts.json) {
32
+ io.json(result);
33
+ return 0;
34
+ }
35
+ if (result.warnings.length)
36
+ text.push("", "warnings", ...result.warnings.map((w) => ` ${w}`));
37
+ const origin = await GitBranchReceiptStore.originOf(io.cwd);
38
+ if (origin) {
39
+ text.push("", "Receipts will live on orphan branches of this repository, one per environment and scope (`sponson-receipts/<env>/<scope>`). Every `sponson apply` pushes a small JSON file to its scope's branch recording what it did and the hashes of what it wrote, so the next run (on any machine, including CI) can detect drift and know what to destroy. These branches share no history with your code, are never merged, and use the same credentials you already push with.");
40
+ }
41
+ io.stdout.write(text.join("\n") + "\n");
42
+ return 0;
43
+ }
44
+ /** Append a line for every unmanaged resource (or only `--adopt`'s) to the existing plan. Returns the text for humans. */
45
+ async function adoptUnmanaged(inv, existing, opts, io, result) {
46
+ const text = [];
47
+ const plan = await planRun(toRunOptions(inv, io));
48
+ result.warnings.push(...inv.warnings, ...plan.warnings);
49
+ let unmanaged = plan.drift.filter((d) => d.kind === "unmanaged");
50
+ if (opts.adopt !== undefined) {
51
+ const wanted = opts.adopt;
52
+ const adoptable = unmanaged.map((d) => d.resource.key);
53
+ unmanaged = unmanaged.filter((d) => [d.resource.key, d.resource.id, d.resource.label].includes(wanted));
54
+ if (unmanaged.length === 0) {
55
+ throw new UsageError(`Nothing to adopt: no unmanaged resource in ${inv.ctx.env}/${inv.ctx.scope} matches \`${wanted}\`. ` +
56
+ (adoptable.length ? `Adoptable keys: ${adoptable.join(", ")}` : "There are no unmanaged resources to adopt."), { adopt: wanted, adoptable });
57
+ }
58
+ }
59
+ const { adoptions, warnings } = adoptChanges(unmanaged, inv.registry, inv.ctx, inv.plan.changes.map((c) => c.id));
60
+ result.warnings.push(...warnings);
61
+ if (adoptions.length > 0) {
62
+ await writeFile(result.path, appendChanges(existing, adoptions.map((a) => a.change)), "utf8");
63
+ result.added = adoptions.map((a) => ({ id: a.change.id, adapter: String(a.change.adapter), op: String(a.change.op), keys: a.keys }));
64
+ }
65
+ if (result.added.length === 0) {
66
+ text.push(`${result.path} already covers everything in ${inv.ctx.env}. Nothing to adopt.`);
67
+ return text;
68
+ }
69
+ text.push(`Added ${result.added.length} line${result.added.length === 1 ? "" : "s"} to ${result.path}: ${result.added.map((a) => a.id).join(", ")}`);
70
+ if (adoptions.some((a) => keepsValues(a.change))) {
71
+ text.push("Adopted variables are written as `{ keep: true }`: Sponson keeps their live values and never destroys them. Replace `{ keep: true }` with a value or `{ secret: \"env://KEY\" }` to let Sponson manage the value.");
72
+ }
73
+ return text;
74
+ }
75
+ // ---------------------------------------------------------------------------
76
+ // Starter plan
77
+ // ---------------------------------------------------------------------------
78
+ /** Detect the stack from the repository's files, write the starter plan composed for it, and summarise. */
79
+ async function writeStarter(planPath, io) {
80
+ const { VERCEL_PROJECT_ID, VERCEL_ORG_ID, NEON_PROJECT_ID, NETLIFY_SITE_ID, CLOUDFLARE_ACCOUNT_ID } = io.env;
81
+ const detection = await detectStack(fsReader(io.cwd), { VERCEL_PROJECT_ID, VERCEL_ORG_ID, NEON_PROJECT_ID, NETLIFY_SITE_ID, CLOUDFLARE_ACCOUNT_ID });
82
+ const starter = composeStarter(detection);
83
+ await writeFile(planPath, starter.text, "utf8");
84
+ const detected = { found: detection.found, unsupported: detection.unsupported, todo: starter.todos, assumed: starter.assumed };
85
+ return { detected, text: [`Wrote ${planPath}`, ...initSummary(detected, credentialsFor(detection))] };
86
+ }
87
+ /** The short human summary: what was found, what is not supported yet, what is left to fill in, what to run next. */
88
+ export function initSummary(d, credentials) {
89
+ const out = [
90
+ d.assumed
91
+ ? `Detected: ${d.found.length ? `${d.found.map((f) => f.name).join(", ")}, but no deploy target or database Sponson manages` : "nothing Sponson manages"}; wrote the Vercel + Neon template`
92
+ : `Detected: ${d.found.map((f) => `${f.name} (${f.evidence[0]})`).join(", ")}`,
93
+ ];
94
+ if (d.unsupported.length)
95
+ out.push("Not supported yet (no line manages them):", ...d.unsupported.map((u) => ` ${u.name} (${u.evidence[0]}): ${u.pointer}`));
96
+ if (d.todo.length)
97
+ out.push("To fill in:", ...d.todo.map((t) => ` ${t.path} (now ${JSON.stringify(t.placeholder)}): ${t.hint}`));
98
+ out.push(`Next: set ${credentials.join(", ")} in your environment, then run \`sponson plan\``);
99
+ return out;
100
+ }
101
+ async function ensureGitignore(cwd) {
102
+ const path = join(cwd, ".gitignore");
103
+ const text = await readFile(path, "utf8").catch(() => "");
104
+ if (text.split(/\r?\n/).some((l) => l.trim() === ".sponson/" || l.trim() === ".sponson"))
105
+ return false;
106
+ await writeFile(path, text === "" || text.endsWith("\n") ? `${text}.sponson/\n` : `${text}\n.sponson/\n`, "utf8");
107
+ return true;
108
+ }
109
+ /**
110
+ * Turn unmanaged drift into plan lines. What a line looks like is provider knowledge, so each op that listed
111
+ * the resources builds its own lines (`OpSpec.adopt`); this only groups, makes ids unique and scopes the lines
112
+ * to the current environment. Resources whose op cannot adopt are reported as warnings, never guessed at.
113
+ */
114
+ export function adoptChanges(unmanaged, registry, ctx, takenIds) {
115
+ const ids = new Set(takenIds);
116
+ const uniqueId = (base) => {
117
+ const root = base.toLowerCase().replace(/[^a-z0-9_-]+/g, "-").replace(/^[^a-z]+/, "") || "adopted";
118
+ let id = root;
119
+ let n = 2;
120
+ while (ids.has(id))
121
+ id = `${root}-${n++}`;
122
+ ids.add(id);
123
+ return id;
124
+ };
125
+ const groups = new Map();
126
+ for (const d of unmanaged) {
127
+ const k = `${d.adapter}\u0000${d.op ?? ""}`;
128
+ const g = groups.get(k) ?? { adapter: d.adapter, op: d.op, drift: [] };
129
+ g.drift.push(d);
130
+ groups.set(k, g);
131
+ }
132
+ const adoptions = [];
133
+ const warnings = [];
134
+ for (const { adapter, op, drift } of groups.values()) {
135
+ const keys = drift.map((d) => d.resource.key).join(", ");
136
+ const spec = op === undefined ? undefined : registry.op(adapter, op);
137
+ if (!spec?.adopt) {
138
+ warnings.push(`cannot adopt ${keys}: adapter ${adapter}${op ? ` (op ${op})` : ""} has no adopt()`);
139
+ continue;
140
+ }
141
+ for (const line of spec.adopt(drift.map((d) => d.resource), ctx)) {
142
+ adoptions.push({ change: { id: uniqueId(line.id), adapter, op: op, ...line.params, environments: [ctx.env] }, keys: line.keys });
143
+ }
144
+ }
145
+ return { adoptions, warnings };
146
+ }
147
+ /** Whether a line adopts values as `{ keep: true }` (and so needs the note on how to take them over). */
148
+ function keepsValues(change) {
149
+ let found = false;
150
+ walkParams(change, [], (_p, v) => {
151
+ if (isKeepRef(v))
152
+ found = true;
153
+ });
154
+ return found;
155
+ }
156
+ /**
157
+ * Append lines to `changes:` as text. Each new line is rendered on its own and spliced in after the last
158
+ * existing line of the list, so every byte already in the file (comments, quoting, flow maps, blank lines)
159
+ * stays exactly as it was.
160
+ */
161
+ export function appendChanges(source, changes) {
162
+ if (changes.length === 0)
163
+ return source;
164
+ const seq = parseDocument(source).get("changes", true);
165
+ const block = (indent) => renderChanges(changes, indent);
166
+ if (seq === undefined)
167
+ return addChangesKey(source, block(2));
168
+ if (isScalar(seq) && (seq.value === null || seq.value === ""))
169
+ return fillEmptyChanges(source, block(2));
170
+ if (!isSeq(seq) || !seq.range)
171
+ throw new UsageError("`changes:` in the plan is not a list; fix the plan before adopting");
172
+ if (seq.flow) {
173
+ if (seq.items.length > 0)
174
+ throw new UsageError("`changes:` is written as a flow list (`[...]`) with items; rewrite it as a block list to adopt into it");
175
+ return replaceEmptyFlowList(source, seq.range, block(2));
176
+ }
177
+ return extendBlockList(source, seq.range, block);
178
+ }
179
+ /** No `changes:` key at all: add the list at the end of the file. */
180
+ function addChangesKey(source, block) {
181
+ const base = source === "" || source.endsWith("\n") ? source : `${source}\n`;
182
+ return `${base}changes:${block}`;
183
+ }
184
+ /** `changes:` with nothing under it: the list goes right after that line. */
185
+ function fillEmptyChanges(source, block) {
186
+ const keyAt = source.search(/^changes:/m);
187
+ if (keyAt < 0)
188
+ throw new UsageError("`changes:` must be a top-level key of the plan");
189
+ const eol = source.indexOf("\n", keyAt);
190
+ const head = eol < 0 ? source : source.slice(0, eol);
191
+ return head + block.replace(/\n$/, "") + (eol < 0 ? "\n" : source.slice(eol));
192
+ }
193
+ /** `changes: []`: a block list in place of the brackets. */
194
+ function replaceEmptyFlowList(source, [start, end], block) {
195
+ const rest = source.slice(end);
196
+ return source.slice(0, start).replace(/[ \t]+$/, "") + block.replace(/\n$/, "") + (rest.startsWith("\n") ? rest : `\n${rest}`);
197
+ }
198
+ /** A block list: new items go after its last item, at the list's own indentation. */
199
+ function extendBlockList(source, [start, end], block) {
200
+ const indent = start - (source.lastIndexOf("\n", start - 1) + 1);
201
+ const head = source.slice(0, end);
202
+ return (head.endsWith("\n") ? head : `${head}\n`) + block(indent).replace(/\n$/, "") + "\n" + source.slice(end);
203
+ }
204
+ /** Each change as a block-list item at `indent`, each preceded by a newline. */
205
+ function renderChanges(changes, indent) {
206
+ return changes
207
+ .map((c) => {
208
+ const item = new Document([c]);
209
+ visit(item, { Pair: (_k, pair) => compactPair(pair) });
210
+ const text = item.toString({ lineWidth: 0 }).replace(/\n+$/, "");
211
+ return "\n" + text.split("\n").map((l) => (l === "" ? l : " ".repeat(indent) + l)).join("\n") + "\n";
212
+ })
213
+ .join("");
214
+ }
215
+ /** `environments: [preview]` and reference forms read as one value: `NAME: { keep: true }`, not a nested block. */
216
+ function compactPair(pair) {
217
+ if (isScalar(pair.key) && pair.key.value === "environments" && isSeq(pair.value))
218
+ pair.value.flow = true;
219
+ const only = isMap(pair.value) && pair.value.items.length === 1 ? pair.value.items[0].key : undefined;
220
+ if (isMap(pair.value) && isScalar(only) && ["keep", "secret", "from"].includes(String(only.value)))
221
+ pair.value.flow = true;
222
+ }
223
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAsD,MAAM,eAAe,CAAC;AAC1I,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAa,MAAM,MAAM,CAAC;AACzF,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,cAAc,EAA6C,MAAM,eAAe,CAAC;AACjI,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAyC,MAAM,aAAa,CAAC;AAC3F,OAAO,EAAE,cAAc,EAAE,cAAc,EAAa,MAAM,eAAe,CAAC;AAkC1E;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IAAc,EAAE,EAAM,EAAE,QAAkB;IAC1E,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACvC,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE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