@context-forge/core 0.19.16 → 0.19.18

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 (203) hide show
  1. package/dist/adoption/adoptionCompletion.d.ts +16 -0
  2. package/dist/adoption/adoptionCompletion.d.ts.map +1 -0
  3. package/dist/adoption/adoptionCompletion.js +37 -0
  4. package/dist/adoption/adoptionCompletion.js.map +1 -0
  5. package/dist/adoption/adoptionFacts.d.ts +25 -0
  6. package/dist/adoption/adoptionFacts.d.ts.map +1 -0
  7. package/dist/adoption/adoptionFacts.js +149 -0
  8. package/dist/adoption/adoptionFacts.js.map +1 -0
  9. package/dist/adoption/adoptionOutcome.d.ts +40 -0
  10. package/dist/adoption/adoptionOutcome.d.ts.map +1 -0
  11. package/dist/adoption/adoptionOutcome.js +30 -0
  12. package/dist/adoption/adoptionOutcome.js.map +1 -0
  13. package/dist/adoption/adoptionResolver.d.ts +8 -0
  14. package/dist/adoption/adoptionResolver.d.ts.map +1 -0
  15. package/dist/adoption/adoptionResolver.js +152 -0
  16. package/dist/adoption/adoptionResolver.js.map +1 -0
  17. package/dist/adoption/adoptionState.d.ts +7 -0
  18. package/dist/adoption/adoptionState.d.ts.map +1 -0
  19. package/dist/adoption/adoptionState.js +24 -0
  20. package/dist/adoption/adoptionState.js.map +1 -0
  21. package/dist/adoption/contracts.d.ts +24 -0
  22. package/dist/adoption/contracts.d.ts.map +1 -0
  23. package/dist/adoption/contracts.js +14 -0
  24. package/dist/adoption/contracts.js.map +1 -0
  25. package/dist/adoption/index.d.ts +7 -0
  26. package/dist/adoption/index.d.ts.map +1 -0
  27. package/dist/adoption/index.js +7 -0
  28. package/dist/adoption/index.js.map +1 -0
  29. package/dist/config/ConfigKeys.d.ts +2 -0
  30. package/dist/config/ConfigKeys.d.ts.map +1 -1
  31. package/dist/config/ConfigKeys.js +18 -0
  32. package/dist/config/ConfigKeys.js.map +1 -1
  33. package/dist/config/index.d.ts +1 -1
  34. package/dist/config/index.d.ts.map +1 -1
  35. package/dist/config/index.js +1 -1
  36. package/dist/config/index.js.map +1 -1
  37. package/dist/detection/buildManifest.d.ts +4 -0
  38. package/dist/detection/buildManifest.d.ts.map +1 -0
  39. package/dist/detection/buildManifest.js +21 -0
  40. package/dist/detection/buildManifest.js.map +1 -0
  41. package/dist/detection/ciDetection.d.ts +15 -0
  42. package/dist/detection/ciDetection.d.ts.map +1 -0
  43. package/dist/detection/ciDetection.js +71 -0
  44. package/dist/detection/ciDetection.js.map +1 -0
  45. package/dist/detection/comprehensionAnalysis.d.ts +7 -0
  46. package/dist/detection/comprehensionAnalysis.d.ts.map +1 -0
  47. package/dist/detection/comprehensionAnalysis.js +59 -0
  48. package/dist/detection/comprehensionAnalysis.js.map +1 -0
  49. package/dist/detection/history.d.ts +12 -0
  50. package/dist/detection/history.d.ts.map +1 -0
  51. package/dist/detection/history.js +22 -0
  52. package/dist/detection/history.js.map +1 -0
  53. package/dist/detection/index.d.ts +10 -0
  54. package/dist/detection/index.d.ts.map +1 -0
  55. package/dist/detection/index.js +10 -0
  56. package/dist/detection/index.js.map +1 -0
  57. package/dist/detection/pathPresent.d.ts +9 -0
  58. package/dist/detection/pathPresent.d.ts.map +1 -0
  59. package/dist/detection/pathPresent.js +29 -0
  60. package/dist/detection/pathPresent.js.map +1 -0
  61. package/dist/detection/planningArtifacts.d.ts +17 -0
  62. package/dist/detection/planningArtifacts.d.ts.map +1 -0
  63. package/dist/detection/planningArtifacts.js +72 -0
  64. package/dist/detection/planningArtifacts.js.map +1 -0
  65. package/dist/detection/presentPaths.d.ts +11 -0
  66. package/dist/detection/presentPaths.d.ts.map +1 -0
  67. package/dist/detection/presentPaths.js +40 -0
  68. package/dist/detection/presentPaths.js.map +1 -0
  69. package/dist/detection/sourceVolume.d.ts +16 -0
  70. package/dist/detection/sourceVolume.d.ts.map +1 -0
  71. package/dist/detection/sourceVolume.js +93 -0
  72. package/dist/detection/sourceVolume.js.map +1 -0
  73. package/dist/detection/squadronProbe.d.ts +56 -0
  74. package/dist/detection/squadronProbe.d.ts.map +1 -0
  75. package/dist/detection/squadronProbe.js +103 -0
  76. package/dist/detection/squadronProbe.js.map +1 -0
  77. package/dist/docs-map/discoverDocs.d.ts +14 -0
  78. package/dist/docs-map/discoverDocs.d.ts.map +1 -0
  79. package/dist/docs-map/discoverDocs.js +122 -0
  80. package/dist/docs-map/discoverDocs.js.map +1 -0
  81. package/dist/docs-map/docsMapError.d.ts +11 -0
  82. package/dist/docs-map/docsMapError.d.ts.map +1 -0
  83. package/dist/docs-map/docsMapError.js +23 -0
  84. package/dist/docs-map/docsMapError.js.map +1 -0
  85. package/dist/docs-map/docsMapFile.d.ts +24 -0
  86. package/dist/docs-map/docsMapFile.d.ts.map +1 -0
  87. package/dist/docs-map/docsMapFile.js +142 -0
  88. package/dist/docs-map/docsMapFile.js.map +1 -0
  89. package/dist/docs-map/index.d.ts +4 -0
  90. package/dist/docs-map/index.d.ts.map +1 -0
  91. package/dist/docs-map/index.js +3 -0
  92. package/dist/docs-map/index.js.map +1 -0
  93. package/dist/docs-map/renderDocsMap.d.ts +10 -0
  94. package/dist/docs-map/renderDocsMap.d.ts.map +1 -0
  95. package/dist/docs-map/renderDocsMap.js +44 -0
  96. package/dist/docs-map/renderDocsMap.js.map +1 -0
  97. package/dist/guides/guideMinimum.d.ts +8 -0
  98. package/dist/guides/guideMinimum.d.ts.map +1 -0
  99. package/dist/guides/guideMinimum.js +28 -0
  100. package/dist/guides/guideMinimum.js.map +1 -0
  101. package/dist/guides/index.d.ts +1 -0
  102. package/dist/guides/index.d.ts.map +1 -1
  103. package/dist/guides/index.js +1 -0
  104. package/dist/guides/index.js.map +1 -1
  105. package/dist/index.d.ts +1 -0
  106. package/dist/index.d.ts.map +1 -1
  107. package/dist/index.js +2 -0
  108. package/dist/index.js.map +1 -1
  109. package/dist/introspection/ArtifactIntrospector.d.ts +2 -0
  110. package/dist/introspection/ArtifactIntrospector.d.ts.map +1 -1
  111. package/dist/introspection/ArtifactIntrospector.js +3 -1
  112. package/dist/introspection/ArtifactIntrospector.js.map +1 -1
  113. package/dist/introspection/ConsistencyChecker.d.ts.map +1 -1
  114. package/dist/introspection/ConsistencyChecker.js +15 -4
  115. package/dist/introspection/ConsistencyChecker.js.map +1 -1
  116. package/dist/introspection/WorkflowNavigator.d.ts +19 -15
  117. package/dist/introspection/WorkflowNavigator.d.ts.map +1 -1
  118. package/dist/introspection/WorkflowNavigator.js +159 -57
  119. package/dist/introspection/WorkflowNavigator.js.map +1 -1
  120. package/dist/introspection/adoptionNavigation.d.ts +40 -0
  121. package/dist/introspection/adoptionNavigation.d.ts.map +1 -0
  122. package/dist/introspection/adoptionNavigation.js +190 -0
  123. package/dist/introspection/adoptionNavigation.js.map +1 -0
  124. package/dist/introspection/parsers/existingStatePlan.d.ts +7 -0
  125. package/dist/introspection/parsers/existingStatePlan.d.ts.map +1 -0
  126. package/dist/introspection/parsers/existingStatePlan.js +22 -0
  127. package/dist/introspection/parsers/existingStatePlan.js.map +1 -0
  128. package/dist/introspection/parsers/slicePlanParser.d.ts.map +1 -1
  129. package/dist/introspection/parsers/slicePlanParser.js +10 -1
  130. package/dist/introspection/parsers/slicePlanParser.js.map +1 -1
  131. package/dist/introspection/retroactiveRules.d.ts +17 -0
  132. package/dist/introspection/retroactiveRules.d.ts.map +1 -0
  133. package/dist/introspection/retroactiveRules.js +100 -0
  134. package/dist/introspection/retroactiveRules.js.map +1 -0
  135. package/dist/introspection/reviewGate.d.ts +24 -1
  136. package/dist/introspection/reviewGate.d.ts.map +1 -1
  137. package/dist/introspection/reviewGate.js +24 -0
  138. package/dist/introspection/reviewGate.js.map +1 -1
  139. package/dist/introspection/setupCiOffer.d.ts +9 -0
  140. package/dist/introspection/setupCiOffer.d.ts.map +1 -0
  141. package/dist/introspection/setupCiOffer.js +48 -0
  142. package/dist/introspection/setupCiOffer.js.map +1 -0
  143. package/dist/introspection/statusDerivation.d.ts +19 -1
  144. package/dist/introspection/statusDerivation.d.ts.map +1 -1
  145. package/dist/introspection/statusDerivation.js +24 -0
  146. package/dist/introspection/statusDerivation.js.map +1 -1
  147. package/dist/introspection/types.d.ts +18 -0
  148. package/dist/introspection/types.d.ts.map +1 -1
  149. package/dist/introspection/types.js +2 -0
  150. package/dist/introspection/types.js.map +1 -1
  151. package/dist/node.d.ts +5 -0
  152. package/dist/node.d.ts.map +1 -1
  153. package/dist/node.js +9 -0
  154. package/dist/node.js.map +1 -1
  155. package/dist/onboarding/onboardRecipe.d.ts +28 -0
  156. package/dist/onboarding/onboardRecipe.d.ts.map +1 -0
  157. package/dist/onboarding/onboardRecipe.js +79 -0
  158. package/dist/onboarding/onboardRecipe.js.map +1 -0
  159. package/dist/ruleReconciliation/index.d.ts +5 -0
  160. package/dist/ruleReconciliation/index.d.ts.map +1 -0
  161. package/dist/ruleReconciliation/index.js +5 -0
  162. package/dist/ruleReconciliation/index.js.map +1 -0
  163. package/dist/ruleReconciliation/markers.d.ts +20 -0
  164. package/dist/ruleReconciliation/markers.d.ts.map +1 -0
  165. package/dist/ruleReconciliation/markers.js +20 -0
  166. package/dist/ruleReconciliation/markers.js.map +1 -0
  167. package/dist/ruleReconciliation/projectSources.d.ts +29 -0
  168. package/dist/ruleReconciliation/projectSources.d.ts.map +1 -0
  169. package/dist/ruleReconciliation/projectSources.js +80 -0
  170. package/dist/ruleReconciliation/projectSources.js.map +1 -0
  171. package/dist/ruleReconciliation/schema.d.ts +24 -0
  172. package/dist/ruleReconciliation/schema.d.ts.map +1 -0
  173. package/dist/ruleReconciliation/schema.js +77 -0
  174. package/dist/ruleReconciliation/schema.js.map +1 -0
  175. package/dist/ruleReconciliation/store.d.ts +6 -0
  176. package/dist/ruleReconciliation/store.d.ts.map +1 -0
  177. package/dist/ruleReconciliation/store.js +56 -0
  178. package/dist/ruleReconciliation/store.js.map +1 -0
  179. package/dist/schema/frontmatterSchema.d.ts +1 -1
  180. package/dist/schema/frontmatterSchema.d.ts.map +1 -1
  181. package/dist/schema/frontmatterSchema.js +3 -0
  182. package/dist/schema/frontmatterSchema.js.map +1 -1
  183. package/dist/schema/projectSchema.d.ts +4 -0
  184. package/dist/schema/projectSchema.d.ts.map +1 -1
  185. package/dist/schema/projectSchema.js +4 -0
  186. package/dist/schema/projectSchema.js.map +1 -1
  187. package/dist/services/ContextIntegrator.d.ts +4 -1
  188. package/dist/services/ContextIntegrator.d.ts.map +1 -1
  189. package/dist/services/ContextIntegrator.js +22 -4
  190. package/dist/services/ContextIntegrator.js.map +1 -1
  191. package/dist/services/ContextTemplateEngine.d.ts.map +1 -1
  192. package/dist/services/ContextTemplateEngine.js +10 -0
  193. package/dist/services/ContextTemplateEngine.js.map +1 -1
  194. package/dist/services/CoreServiceFactory.d.ts +10 -1
  195. package/dist/services/CoreServiceFactory.d.ts.map +1 -1
  196. package/dist/services/CoreServiceFactory.js +11 -2
  197. package/dist/services/CoreServiceFactory.js.map +1 -1
  198. package/dist/services/SectionBuilder.d.ts.map +1 -1
  199. package/dist/services/SectionBuilder.js +3 -0
  200. package/dist/services/SectionBuilder.js.map +1 -1
  201. package/dist/types/context.d.ts +4 -0
  202. package/dist/types/context.d.ts.map +1 -1
  203. package/package.json +1 -1
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Absolute path of the existing-state slice plan, or null. A plan without a retroactive entry
3
+ * does not count: an adoption that recorded nothing built is not an existing-state plan.
4
+ * Read-only.
5
+ */
6
+ export declare function findRecordedPlan(checkoutPath: string): Promise<string | null>;
7
+ /** Writes `adoption.state: complete`. A failed write throws with the manual remedy (261 D9). */
8
+ export declare function persistAdoptionComplete(checkoutPath: string): Promise<void>;
9
+ /** The design's contract: find, then persist. Exported for 264's `cf next`. */
10
+ export declare function completeAdoptionIfPlanRecorded(checkoutPath: string): Promise<{
11
+ completed: false;
12
+ } | {
13
+ completed: true;
14
+ planPath: string;
15
+ }>;
16
+ //# sourceMappingURL=adoptionCompletion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adoptionCompletion.d.ts","sourceRoot":"","sources":["../../src/adoption/adoptionCompletion.ts"],"names":[],"mappings":"AAYA;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAE7E;AAED,gGAAgG;AAChG,wBAAsB,uBAAuB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAUjF;AAED,+EAA+E;AAC/E,wBAAsB,8BAA8B,CAClD,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC;IAAE,SAAS,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,SAAS,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAKvE"}
@@ -0,0 +1,37 @@
1
+ // Adoption completion (slice 263, D5): adoption is finished once a slice plan with a
2
+ // retroactive entry exists, because that is the observable sign that the existing-state plan
3
+ // has been written. Split into find and persist so the resolver can write after it renders
4
+ // the facts (R1). `findRecordedPlan` delegates to `findExistingStatePlan` (264), the one
5
+ // definition of "a slice plan with a retroactive entry exists".
6
+ import { findExistingStatePlan } from '../introspection/parsers/existingStatePlan.js';
7
+ import { writeAdoptionState } from './adoptionState.js';
8
+ import { AdoptionError } from './contracts.js';
9
+ /** The remedy a failed write names, so the person can finish the transition by hand. */
10
+ const COMPLETE_REMEDY = 'cf config set adoption.state complete';
11
+ /**
12
+ * Absolute path of the existing-state slice plan, or null. A plan without a retroactive entry
13
+ * does not count: an adoption that recorded nothing built is not an existing-state plan.
14
+ * Read-only.
15
+ */
16
+ export function findRecordedPlan(checkoutPath) {
17
+ return findExistingStatePlan(checkoutPath);
18
+ }
19
+ /** Writes `adoption.state: complete`. A failed write throws with the manual remedy (261 D9). */
20
+ export async function persistAdoptionComplete(checkoutPath) {
21
+ try {
22
+ await writeAdoptionState(checkoutPath, 'complete');
23
+ }
24
+ catch (error) {
25
+ const detail = error instanceof Error ? error.message : String(error);
26
+ throw new AdoptionError(`Cannot record adoption state in .context-forge.toml: ${detail}. To finish adoption by hand: ${COMPLETE_REMEDY}`, { cause: error });
27
+ }
28
+ }
29
+ /** The design's contract: find, then persist. Exported for 264's `cf next`. */
30
+ export async function completeAdoptionIfPlanRecorded(checkoutPath) {
31
+ const planPath = await findRecordedPlan(checkoutPath);
32
+ if (planPath === null)
33
+ return { completed: false };
34
+ await persistAdoptionComplete(checkoutPath);
35
+ return { completed: true, planPath };
36
+ }
37
+ //# sourceMappingURL=adoptionCompletion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adoptionCompletion.js","sourceRoot":"","sources":["../../src/adoption/adoptionCompletion.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,6FAA6F;AAC7F,2FAA2F;AAC3F,yFAAyF;AACzF,gEAAgE;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+CAA+C,CAAC;AACtF,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,wFAAwF;AACxF,MAAM,eAAe,GAAG,uCAAuC,CAAC;AAEhE;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,YAAoB;IACnD,OAAO,qBAAqB,CAAC,YAAY,CAAC,CAAC;AAC7C,CAAC;AAED,gGAAgG;AAChG,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,YAAoB;IAChE,IAAI,CAAC;QACH,MAAM,kBAAkB,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;IACrD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,MAAM,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACtE,MAAM,IAAI,aAAa,CACrB,wDAAwD,MAAM,iCAAiC,eAAe,EAAE,EAChH,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAC;IACJ,CAAC;AACH,CAAC;AAED,+EAA+E;AAC/E,MAAM,CAAC,KAAK,UAAU,8BAA8B,CAClD,YAAoB;IAEpB,MAAM,QAAQ,GAAG,MAAM,gBAAgB,CAAC,YAAY,CAAC,CAAC;IACtD,IAAI,QAAQ,KAAK,IAAI;QAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IACnD,MAAM,uBAAuB,CAAC,YAAY,CAAC,CAAC;IAC5C,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AACvC,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { AdoptionState } from '../config/ConfigKeys.js';
2
+ import type { CiRecognition } from '../detection/ciDetection.js';
3
+ import type { HistoryFact } from '../detection/history.js';
4
+ import { type ProbeOutcome } from '../detection/squadronProbe.js';
5
+ import { type AdoptionOutcome } from './adoptionOutcome.js';
6
+ /** Outcome used when an explicit brownfield-adoption instruction skipped detection (D4). */
7
+ export declare const NOT_EVALUATED: {
8
+ readonly kind: "not-evaluated";
9
+ };
10
+ export interface AdoptionFactsInput {
11
+ outcome: AdoptionOutcome | typeof NOT_EVALUATED;
12
+ state: AdoptionState;
13
+ /** True when this build wrote `in_progress`. */
14
+ stateSetByBuild: boolean;
15
+ history: HistoryFact;
16
+ docs: readonly string[];
17
+ adrs: readonly string[];
18
+ ruleFiles: readonly string[];
19
+ ci: CiRecognition;
20
+ probe: ProbeOutcome;
21
+ }
22
+ /** D6: the squadron part of the section, as ready-made bullet lines. */
23
+ export declare function renderSquadronFacts(outcome: ProbeOutcome): string[];
24
+ export declare function renderAdoptionFacts(input: AdoptionFactsInput): string;
25
+ //# sourceMappingURL=adoptionFacts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adoptionFacts.d.ts","sourceRoot":"","sources":["../../src/adoption/adoptionFacts.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D,OAAO,EAIL,KAAK,YAAY,EAElB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAA+B,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGzF,4FAA4F;AAC5F,eAAO,MAAM,aAAa;;CAAqC,CAAC;AAEhE,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,eAAe,GAAG,OAAO,aAAa,CAAC;IAChD,KAAK,EAAE,aAAa,CAAC;IACrB,gDAAgD;IAChD,eAAe,EAAE,OAAO,CAAC;IACzB,OAAO,EAAE,WAAW,CAAC;IACrB,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACxB,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACxB,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IAC7B,EAAE,EAAE,aAAa,CAAC;IAClB,KAAK,EAAE,YAAY,CAAC;CACrB;AAiDD,wEAAwE;AACxE,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,EAAE,CAanE;AAiFD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,kBAAkB,GAAG,MAAM,CAkBrE"}
@@ -0,0 +1,149 @@
1
+ import { SQUADRON_PROBE_MAX_BUFFER_BYTES, SQUADRON_PROBE_TIMEOUT_MS, SUPPORTED_PROBE_VERSION, } from '../detection/squadronProbe.js';
2
+ import { BROWNFIELD_MIN_SOURCE_LINES } from './adoptionOutcome.js';
3
+ import { BROWNFIELD_ADOPTION_INSTRUCTION } from './contracts.js';
4
+ /** Outcome used when an explicit brownfield-adoption instruction skipped detection (D4). */
5
+ export const NOT_EVALUATED = { kind: 'not-evaluated' };
6
+ const NONE_FOUND = 'none found';
7
+ const MILLIS_PER_SECOND = 1000;
8
+ const BYTES_PER_MIB = 1024 * 1024;
9
+ const MIN_FENCE_LENGTH = 3;
10
+ const JSON_INDENT = ' ';
11
+ /** Nested bullets must indent at least the width of the parent `- ` marker. */
12
+ const LIST_INDENT = ' ';
13
+ /** D2: the one place a probe failure becomes text. */
14
+ function describeUnavailableReason(reason) {
15
+ switch (reason.kind) {
16
+ case 'not-found':
17
+ return '`sq` was not found on PATH';
18
+ case 'could-not-run':
19
+ return ('`sq probe` could not run or did not finish within ' +
20
+ `${SQUADRON_PROBE_TIMEOUT_MS / MILLIS_PER_SECOND} s with at most ` +
21
+ `${SQUADRON_PROBE_MAX_BUFFER_BYTES / BYTES_PER_MIB} MiB of output (${reason.detail})`);
22
+ case 'non-zero-exit':
23
+ return `\`sq probe --json\` exited with code ${reason.exitCode}`;
24
+ case 'unreadable-output':
25
+ return '`sq probe --json` printed output that is not a JSON object';
26
+ case 'unsupported-version':
27
+ return `\`sq probe\` reports probe_version ${reason.value}; this cf supports ${SUPPORTED_PROBE_VERSION}`;
28
+ default: {
29
+ const unhandled = reason;
30
+ throw new Error(`Unhandled probe reason: ${JSON.stringify(unhandled)}`);
31
+ }
32
+ }
33
+ }
34
+ /** A fence one backtick longer than the longest backtick run in the text, so it cannot close early. */
35
+ function fenceFor(text) {
36
+ // A loop, not Math.max(...runs): spreading one argument per run overflows the call stack on large input.
37
+ let longestRun = 0;
38
+ for (const run of text.match(/`+/g) ?? [])
39
+ longestRun = Math.max(longestRun, run.length);
40
+ return '`'.repeat(Math.max(MIN_FENCE_LENGTH, longestRun + 1));
41
+ }
42
+ function renderProbeWarnings(warnings) {
43
+ const label = '- Probe warnings (stderr, verbatim):';
44
+ if (warnings.length === 0)
45
+ return [`${label} none`];
46
+ return [label, ...warnings.map((line) => `${LIST_INDENT}- ${line}`)];
47
+ }
48
+ /** D6: the squadron part of the section, as ready-made bullet lines. */
49
+ export function renderSquadronFacts(outcome) {
50
+ if (outcome.kind === 'unavailable') {
51
+ const lines = [`- Squadron: unavailable. ${describeUnavailableReason(outcome.reason)}.`];
52
+ return outcome.warnings.length > 0 ? [...lines, ...renderProbeWarnings(outcome.warnings)] : lines;
53
+ }
54
+ const fence = fenceFor(outcome.json);
55
+ return [
56
+ '- Squadron probe (`sq probe --json`), verbatim:',
57
+ `${JSON_INDENT}${fence}json`,
58
+ ...outcome.json.split('\n').map((line) => `${JSON_INDENT}${line}`),
59
+ `${JSON_INDENT}${fence}`,
60
+ ...renderProbeWarnings(outcome.warnings),
61
+ ];
62
+ }
63
+ function describeSource(source) {
64
+ const lines = source.capped
65
+ ? `${source.lines}+ non-blank source lines (count stopped at the threshold)`
66
+ : `${source.lines} non-blank source lines`;
67
+ return `${lines} in ${source.files} source files`;
68
+ }
69
+ function describeOutcome(outcome) {
70
+ switch (outcome.kind) {
71
+ case 'not-evaluated':
72
+ return `not evaluated (explicit ${BROWNFIELD_ADOPTION_INSTRUCTION} instruction)`;
73
+ case 'adoption-in-progress':
74
+ return 'adoption in progress (adoption.state is in_progress)';
75
+ case 'adoption-completed':
76
+ return 'adoption completed by this build';
77
+ case 'adoption-closed':
78
+ return `adoption closed (adoption.state is ${outcome.state})`;
79
+ case 'already-planned':
80
+ return `already planned (${outcome.artifacts.length} planning artifact files exist)`;
81
+ case 'brownfield':
82
+ return `brownfield: ${outcome.source.lines}${outcome.source.capped ? '+' : ''} non-blank source lines ` +
83
+ `(threshold ${BROWNFIELD_MIN_SOURCE_LINES}${outcome.source.capped ? '; count stopped at the threshold' : ''})`;
84
+ case 'greenfield':
85
+ return `greenfield: ${outcome.source.lines} non-blank source lines (threshold ${BROWNFIELD_MIN_SOURCE_LINES})`;
86
+ default: {
87
+ // A new outcome kind (slice 263) fails to compile here until it is handled.
88
+ const unhandled = outcome;
89
+ throw new Error(`Unhandled adoption outcome: ${JSON.stringify(unhandled)}`);
90
+ }
91
+ }
92
+ }
93
+ function describeSourceVolume(outcome) {
94
+ switch (outcome.kind) {
95
+ case 'brownfield':
96
+ case 'greenfield':
97
+ return describeSource(outcome.source);
98
+ case 'not-evaluated':
99
+ case 'adoption-in-progress':
100
+ case 'adoption-completed':
101
+ case 'adoption-closed':
102
+ case 'already-planned':
103
+ return null;
104
+ default: {
105
+ const unhandled = outcome;
106
+ throw new Error(`Unhandled adoption outcome: ${JSON.stringify(unhandled)}`);
107
+ }
108
+ }
109
+ }
110
+ function describeHistory(history) {
111
+ if (history.kind === 'unknown')
112
+ return `unknown: ${history.reason}`;
113
+ return `${history.commits} commits${history.shallow ? ' (shallow clone: history is truncated)' : ''}`;
114
+ }
115
+ function listOrNone(items) {
116
+ return items.length > 0 ? items.join(', ') : NONE_FOUND;
117
+ }
118
+ function describeState(state, stateSetByBuild, outcome) {
119
+ const shown = state === '' ? 'unset' : state;
120
+ if (outcome.kind === 'adoption-completed') {
121
+ return (`adoption.state: ${shown}. adoption.state was set to ${shown} by this build: ` +
122
+ `existing-state slice plan found at ${outcome.planPath}. ` +
123
+ 'Adoption is finished; run `cf next` for the next step.');
124
+ }
125
+ if (!stateSetByBuild)
126
+ return `adoption.state: ${shown}`;
127
+ return (`adoption.state: ${shown}. adoption.state was set to in_progress by this build. ` +
128
+ 'To treat the project as new instead: `cf config set adoption.state declined`.');
129
+ }
130
+ export function renderAdoptionFacts(input) {
131
+ const sourceVolume = describeSourceVolume(input.outcome);
132
+ const bullets = [
133
+ `Outcome: ${describeOutcome(input.outcome)}`,
134
+ describeState(input.state, input.stateSetByBuild, input.outcome),
135
+ ...(sourceVolume === null ? [] : [`Source volume: ${sourceVolume}`]),
136
+ `History: ${describeHistory(input.history)}`,
137
+ `Docs: ${listOrNone(input.docs)}`,
138
+ `ADRs: ${listOrNone(input.adrs)}`,
139
+ `Rule files: ${listOrNone(input.ruleFiles)}`,
140
+ `CI: ${listOrNone(input.ci.matches)}`,
141
+ ];
142
+ return [
143
+ '### Adoption Facts',
144
+ '',
145
+ ...bullets.map((bullet) => `- ${bullet}`),
146
+ ...renderSquadronFacts(input.probe),
147
+ ].join('\n');
148
+ }
149
+ //# sourceMappingURL=adoptionFacts.js.map
@@ -0,0 +1 @@
1
+ {"version":3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G,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,KAAK,MAAM,EAAE,CAAC;QACzC,GAAG,mBAAmB,CAAC,KAAK,CAAC,KAAK,CAAC;KACpC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
@@ -0,0 +1,40 @@
1
+ import type { AdoptionState } from '../config/ConfigKeys.js';
2
+ import type { SourceVolume } from '../detection/sourceVolume.js';
3
+ /**
4
+ * Brownfield iff the project folder holds at least this many non-blank source lines (D1).
5
+ * The one place the threshold is written; deliberately not configurable (the
6
+ * `adoption.state` override is the safety valve).
7
+ */
8
+ export declare const BROWNFIELD_MIN_SOURCE_LINES = 2000;
9
+ export type AdoptionOutcome = {
10
+ kind: 'adoption-in-progress';
11
+ } | {
12
+ kind: 'adoption-completed';
13
+ planPath: string;
14
+ } | {
15
+ kind: 'adoption-closed';
16
+ state: 'complete' | 'declined';
17
+ } | {
18
+ kind: 'already-planned';
19
+ artifacts: string[];
20
+ } | {
21
+ kind: 'brownfield';
22
+ source: SourceVolume;
23
+ } | {
24
+ kind: 'greenfield';
25
+ source: SourceVolume;
26
+ };
27
+ export interface OutcomeInput {
28
+ state: AdoptionState;
29
+ /** Planning artifacts found; read only when `state` is unset. */
30
+ artifacts?: string[];
31
+ /** Source volume; read only when `state` is unset and nothing is planned. */
32
+ source?: SourceVolume;
33
+ }
34
+ /**
35
+ * The outcome order (D1): persisted state → already planned → source volume.
36
+ * Pure. The caller supplies each fact only when the previous one did not decide;
37
+ * a fact the order needs but the caller left out is a programming error.
38
+ */
39
+ export declare function decideOutcome(input: OutcomeInput): AdoptionOutcome;
40
+ //# sourceMappingURL=adoptionOutcome.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adoptionOutcome.d.ts","sourceRoot":"","sources":["../../src/adoption/adoptionOutcome.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAEjE;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,OAAO,CAAC;AAEhD,MAAM,MAAM,eAAe,GACvB;IAAE,IAAI,EAAE,sBAAsB,CAAA;CAAE,GAEhC;IAAE,IAAI,EAAE,oBAAoB,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAChD;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAAA;CAAE,GAC3D;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,SAAS,EAAE,MAAM,EAAE,CAAA;CAAE,GAChD;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,YAAY,CAAA;CAAE,GAC5C;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,YAAY,CAAA;CAAE,CAAC;AAEjD,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,aAAa,CAAC;IACrB,iEAAiE;IACjE,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,6EAA6E;IAC7E,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,YAAY,GAAG,eAAe,CAgBlE"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Brownfield iff the project folder holds at least this many non-blank source lines (D1).
3
+ * The one place the threshold is written; deliberately not configurable (the
4
+ * `adoption.state` override is the safety valve).
5
+ */
6
+ export const BROWNFIELD_MIN_SOURCE_LINES = 2000;
7
+ /**
8
+ * The outcome order (D1): persisted state → already planned → source volume.
9
+ * Pure. The caller supplies each fact only when the previous one did not decide;
10
+ * a fact the order needs but the caller left out is a programming error.
11
+ */
12
+ export function decideOutcome(input) {
13
+ const { state, artifacts, source } = input;
14
+ if (state === 'in_progress')
15
+ return { kind: 'adoption-in-progress' };
16
+ if (state === 'complete' || state === 'declined')
17
+ return { kind: 'adoption-closed', state };
18
+ if (artifacts === undefined) {
19
+ throw new Error('decideOutcome: state is unset, so `artifacts` is required');
20
+ }
21
+ if (artifacts.length > 0)
22
+ return { kind: 'already-planned', artifacts };
23
+ if (source === undefined) {
24
+ throw new Error('decideOutcome: state is unset and nothing is planned, so `source` is required');
25
+ }
26
+ return source.lines >= BROWNFIELD_MIN_SOURCE_LINES
27
+ ? { kind: 'brownfield', source }
28
+ : { kind: 'greenfield', source };
29
+ }
30
+ //# sourceMappingURL=adoptionOutcome.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adoptionOutcome.js","sourceRoot":"","sources":["../../src/adoption/adoptionOutcome.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,IAAI,CAAC;AAmBhD;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,KAAmB;IAC/C,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IAC3C,IAAI,KAAK,KAAK,aAAa;QAAE,OAAO,EAAE,IAAI,EAAE,sBAAsB,EAAE,CAAC;IACrE,IAAI,KAAK,KAAK,UAAU,IAAI,KAAK,KAAK,UAAU;QAAE,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAAC;IAE5F,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;IAC/E,CAAC;IACD,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,SAAS,EAAE,CAAC;IAExE,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,+EAA+E,CAAC,CAAC;IACnG,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,IAAI,2BAA2B;QAChD,CAAC,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE;QAChC,CAAC,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC;AACrC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { type AdoptionResolver, type SquadronProbe } from './contracts.js';
2
+ /** `persist`: a first brownfield detection writes `in_progress`. `read-only`: it never writes. */
3
+ export type AdoptionStateWrites = 'persist' | 'read-only';
4
+ export declare function createAdoptionResolver(options: {
5
+ stateWrites: AdoptionStateWrites;
6
+ squadronProbe: SquadronProbe;
7
+ }): AdoptionResolver;
8
+ //# sourceMappingURL=adoptionResolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adoptionResolver.d.ts","sourceRoot":"","sources":["../../src/adoption/adoptionResolver.ts"],"names":[],"mappings":"AAqBA,OAAO,EAGL,KAAK,gBAAgB,EACrB,KAAK,aAAa,EACnB,MAAM,gBAAgB,CAAC;AAExB,kGAAkG;AAClG,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG,WAAW,CAAC;AAkI1D,wBAAgB,sBAAsB,CAAC,OAAO,EAAE;IAC9C,WAAW,EAAE,mBAAmB,CAAC;IACjC,aAAa,EAAE,aAAa,CAAC;CAC9B,GAAG,gBAAgB,CA4BnB"}
@@ -0,0 +1,152 @@
1
+ // Build-time adoption resolver (slice 261, D4 + D7). The one home of the selection
2
+ // rule and of the build's step order; decideOutcome and the renderer only consume
3
+ // what is gathered here.
4
+ import { readFile } from 'fs/promises';
5
+ import { relative, resolve } from 'path';
6
+ import { COMPREHENSION_PROFILE_VARIABLE, findComprehensionAnalysis } from '../detection/comprehensionAnalysis.js';
7
+ import { findPlanningArtifacts } from '../detection/planningArtifacts.js';
8
+ import { readHistory } from '../detection/history.js';
9
+ import { ADR_DIRS, DOC_PATHS, RULE_FILE_PATHS, presentPaths } from '../detection/presentPaths.js';
10
+ import { recognizeCi } from '../detection/ciDetection.js';
11
+ import { measureSourceVolume } from '../detection/sourceVolume.js';
12
+ import { MIN_GUIDE_VERSION } from '../guides/guideMinimum.js';
13
+ import { CONCEPT_PHASE, resolvePhaseValue } from '../schema/projectSchema.js';
14
+ import { ContextProfileParser } from '../services/ContextProfileParser.js';
15
+ import { resolvePromptFilePath } from '../services/promptFilePath.js';
16
+ import { SystemPromptParser } from '../services/SystemPromptParser.js';
17
+ import { findRecordedPlan, persistAdoptionComplete } from './adoptionCompletion.js';
18
+ import { NOT_EVALUATED, renderAdoptionFacts } from './adoptionFacts.js';
19
+ import { decideOutcome } from './adoptionOutcome.js';
20
+ import { readAdoptionState, writeAdoptionState } from './adoptionState.js';
21
+ import { AdoptionError, BROWNFIELD_ADOPTION_INSTRUCTION, } from './contracts.js';
22
+ const DECLINE_REMEDY = 'To treat the project as new instead: cf config set adoption.state declined';
23
+ /** Step 2: each fact is read only if the previous one did not decide. */
24
+ async function decide(checkoutPath, explicit, stateWrites) {
25
+ const state = await readAdoptionState(checkoutPath);
26
+ if (explicit)
27
+ return { state, outcome: NOT_EVALUATED };
28
+ // 263 D5: an in-progress adoption completes when the existing-state slice plan has been recorded.
29
+ // Read-only builds (template_preview) never complete. The write happens after the facts render (R1).
30
+ if (state === 'in_progress' && stateWrites === 'persist') {
31
+ const planPath = await findRecordedPlan(checkoutPath);
32
+ if (planPath !== null) {
33
+ return { state, outcome: { kind: 'adoption-completed', planPath: relative(resolve(checkoutPath), planPath) } };
34
+ }
35
+ }
36
+ if (state !== '')
37
+ return { state, outcome: decideOutcome({ state }) };
38
+ const artifacts = await findPlanningArtifacts(checkoutPath);
39
+ if (artifacts.length > 0)
40
+ return { state, outcome: decideOutcome({ state, artifacts }) };
41
+ const source = await measureSourceVolume(checkoutPath);
42
+ return { state, outcome: decideOutcome({ state, artifacts, source }) };
43
+ }
44
+ /** Step 3: the brownfield prompt is selected for a brownfield outcome, a resumed adoption or an explicit instruction. */
45
+ function isSelected(outcome) {
46
+ switch (outcome.kind) {
47
+ case 'brownfield':
48
+ case 'adoption-in-progress':
49
+ case 'adoption-completed':
50
+ case 'not-evaluated':
51
+ return true;
52
+ case 'adoption-closed':
53
+ case 'already-planned':
54
+ case 'greenfield':
55
+ return false;
56
+ default: {
57
+ const unhandled = outcome;
58
+ throw new Error(`Unhandled adoption outcome: ${JSON.stringify(unhandled)}`);
59
+ }
60
+ }
61
+ }
62
+ function missingGuidePart(part) {
63
+ return new AdoptionError(`This project is being adopted as an existing codebase, but the installed ai-project-guide has no ` +
64
+ `${BROWNFIELD_ADOPTION_INSTRUCTION} ${part}. Run: cf guides update (needs v${MIN_GUIDE_VERSION}+). ${DECLINE_REMEDY}`);
65
+ }
66
+ /** Step 4 (D9): the guide the build reads must carry both the profile and the prompt. Returns the profile's variables. */
67
+ async function assertGuideSupportsAdoption(projectPath) {
68
+ const promptFile = resolvePromptFilePath(projectPath);
69
+ const profiles = new ContextProfileParser().parseProfiles(await readFile(promptFile, 'utf-8'));
70
+ const profileVariables = profiles[BROWNFIELD_ADOPTION_INSTRUCTION];
71
+ if (profileVariables === undefined)
72
+ throw missingGuidePart('profile');
73
+ const prompt = await new SystemPromptParser(promptFile).getPromptForInstruction(BROWNFIELD_ADOPTION_INSTRUCTION);
74
+ if (prompt === null)
75
+ throw missingGuidePart('prompt');
76
+ return profileVariables;
77
+ }
78
+ /** Step 5 (D9): a failed write stops the build; building anyway would lose adoption on the next build. */
79
+ async function persistInProgress(checkoutPath) {
80
+ try {
81
+ await writeAdoptionState(checkoutPath, 'in_progress');
82
+ }
83
+ catch (error) {
84
+ const detail = error instanceof Error ? error.message : String(error);
85
+ throw new AdoptionError(`Cannot record adoption state in .context-forge.toml: ${detail}. ` +
86
+ `Build the brownfield prompt without saving: cf build --it ${BROWNFIELD_ADOPTION_INSTRUCTION}. ${DECLINE_REMEDY}`, { cause: error });
87
+ }
88
+ }
89
+ /** CI files relative to the checkout, like the other path facts (a repository-root file reads ../..). */
90
+ function relativeCi(checkoutPath) {
91
+ const ci = recognizeCi(checkoutPath);
92
+ const base = resolve(checkoutPath);
93
+ return { ...ci, matches: ci.matches.map((match) => relative(base, match)) };
94
+ }
95
+ /** The state the facts show: what this build is about to write, else what is persisted (R5). */
96
+ function stateShownFor(decision, stateSetByBuild) {
97
+ if (decision.outcome.kind === 'adoption-completed')
98
+ return 'complete';
99
+ return stateSetByBuild ? 'in_progress' : decision.state;
100
+ }
101
+ /** Step 6: the render-only facts and the comprehension pointer, gathered only for a selected build. */
102
+ async function renderFacts(checkoutPath, decision, stateSetByBuild, options) {
103
+ // The comprehension document is resolved only when the guide's profile carries it (D5).
104
+ const wantsComprehension = options.profileVariables.includes(COMPREHENSION_PROFILE_VARIABLE);
105
+ const [history, probe, fileComprehension] = await Promise.all([
106
+ readHistory(checkoutPath),
107
+ options.squadronProbe(checkoutPath),
108
+ wantsComprehension ? findComprehensionAnalysis(checkoutPath) : undefined,
109
+ ]);
110
+ const facts = renderAdoptionFacts({
111
+ outcome: decision.outcome,
112
+ state: stateShownFor(decision, stateSetByBuild),
113
+ stateSetByBuild,
114
+ history,
115
+ probe,
116
+ docs: presentPaths(checkoutPath, DOC_PATHS),
117
+ adrs: presentPaths(checkoutPath, ADR_DIRS),
118
+ ruleFiles: presentPaths(checkoutPath, RULE_FILE_PATHS),
119
+ ci: relativeCi(checkoutPath),
120
+ });
121
+ return { facts, fileComprehension };
122
+ }
123
+ export function createAdoptionResolver(options) {
124
+ return async (projectPath, checkoutPath, instruction) => {
125
+ // Step 1: eligible only where the concept prompt would run (D4); no I/O otherwise.
126
+ const explicit = instruction === BROWNFIELD_ADOPTION_INSTRUCTION;
127
+ if (!explicit && resolvePhaseValue(instruction) !== CONCEPT_PHASE)
128
+ return { selected: false };
129
+ const decision = await decide(checkoutPath, explicit, options.stateWrites);
130
+ if (!isSelected(decision.outcome))
131
+ return { selected: false };
132
+ const profileVariables = await assertGuideSupportsAdoption(projectPath);
133
+ // Gather the facts before writing: a probe failure must not leave in_progress persisted
134
+ // for a build that produced no prompt.
135
+ const stateSetByBuild = decision.outcome.kind === 'brownfield' && options.stateWrites === 'persist';
136
+ const { facts, fileComprehension } = await renderFacts(checkoutPath, decision, stateSetByBuild, {
137
+ squadronProbe: options.squadronProbe,
138
+ profileVariables,
139
+ });
140
+ if (stateSetByBuild)
141
+ await persistInProgress(checkoutPath);
142
+ if (decision.outcome.kind === 'adoption-completed')
143
+ await persistAdoptionComplete(checkoutPath);
144
+ return {
145
+ selected: true,
146
+ instruction: BROWNFIELD_ADOPTION_INSTRUCTION,
147
+ facts,
148
+ ...(fileComprehension === undefined ? {} : { fileComprehension }),
149
+ };
150
+ };
151
+ }
152
+ //# sourceMappingURL=adoptionResolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adoptionResolver.js","sourceRoot":"","sources":["../../src/adoption/adoptionResolver.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,kFAAkF;AAClF,yBAAyB;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEzC,OAAO,EAAE,8BAA8B,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AAClH,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAClG,OAAO,EAAE,WAAW,EAAsB,MAAM,6BAA6B,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAA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aAAa;YAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;QAE9F,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,YAAY,EAAE,QAAQ,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;QAC3E,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC;YAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;QAE9D,MAAM,gBAAgB,GAAG,MAAM,2BAA2B,CAAC,WAAW,CAAC,CAAC;QAExE,wFAAwF;QACxF,uCAAuC;QACvC,MAAM,eAAe,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAK,YAAY,IAAI,OAAO,CAAC,WAAW,KAAK,SAAS,CAAC;QACpG,MAAM,EAAE,KAAK,EAAE,iBAAiB,EAAE,GAAG,MAAM,WAAW,CAAC,YAAY,EAAE,QAAQ,EAAE,eAAe,EAAE;YAC9F,aAAa,EAAE,OAAO,CAAC,aAAa;YACpC,gBAAgB;SACjB,CAAC,CAAC;QACH,IAAI,eAAe;YAAE,MAAM,iBAAiB,CAAC,YAAY,CAAC,CAAC;QAC3D,IAAI,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAK,oBAAoB;YAAE,MAAM,uBAAuB,CAAC,YAAY,CAAC,CAAC;QAEhG,OAAO;YACL,QAAQ,EAAE,IAAI;YACd,WAAW,EAAE,+BAA+B;YAC5C,KAAK;YACL,GAAG,CAAC,iBAAiB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,CAAC;SAClE,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { ADOPTION_STATES, type AdoptionState } from '../config/ConfigKeys.js';
2
+ export { ADOPTION_STATES, type AdoptionState };
3
+ /** Reads the persisted adoption state. A malformed TOML file propagates the parser's error. */
4
+ export declare function readAdoptionState(root: string): Promise<AdoptionState>;
5
+ /** Persists the state to the shared project file. Does not catch: callers own the failure message. */
6
+ export declare function writeAdoptionState(root: string, state: AdoptionState): Promise<void>;
7
+ //# sourceMappingURL=adoptionState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adoptionState.d.ts","sourceRoot":"","sources":["../../src/adoption/adoptionState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAI9E,OAAO,EAAE,eAAe,EAAE,KAAK,aAAa,EAAE,CAAC;AAS/C,+FAA+F;AAC/F,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAU5E;AAED,sGAAsG;AACtG,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAE1F"}
@@ -0,0 +1,24 @@
1
+ import { ADOPTION_STATES } from '../config/ConfigKeys.js';
2
+ import { ConfigManager } from '../config/ConfigManager.js';
3
+ import { AdoptionError } from './contracts.js';
4
+ export { ADOPTION_STATES };
5
+ const ADOPTION_STATE_KEY = 'adoption.state';
6
+ const PROJECT_CONFIG_FILE = '.context-forge.toml';
7
+ function isAdoptionState(value) {
8
+ return ADOPTION_STATES.some((state) => state === value);
9
+ }
10
+ /** Reads the persisted adoption state. A malformed TOML file propagates the parser's error. */
11
+ export async function readAdoptionState(root) {
12
+ const { value } = await new ConfigManager(root).get(ADOPTION_STATE_KEY);
13
+ if (!isAdoptionState(value)) {
14
+ const allowed = ADOPTION_STATES.map((state) => JSON.stringify(state)).join(', ');
15
+ throw new AdoptionError(`adoption.state is ${JSON.stringify(value)}, which is not one of [${allowed}]. ` +
16
+ `Fix or remove the [adoption] section in ${PROJECT_CONFIG_FILE}.`);
17
+ }
18
+ return value;
19
+ }
20
+ /** Persists the state to the shared project file. Does not catch: callers own the failure message. */
21
+ export async function writeAdoptionState(root, state) {
22
+ await new ConfigManager(root).set(ADOPTION_STATE_KEY, state, 'project');
23
+ }
24
+ //# sourceMappingURL=adoptionState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adoptionState.js","sourceRoot":"","sources":["../../src/adoption/adoptionState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAsB,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAsB,CAAC;AAE/C,MAAM,kBAAkB,GAAG,gBAAgB,CAAC;AAC5C,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AAElD,SAAS,eAAe,CAAC,KAAc;IACrC,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,KAAK,CAAC,CAAC;AAC1D,CAAC;AAED,+FAA+F;AAC/F,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,IAAY;IAClD,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,aAAa,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IACxE,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,OAAO,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjF,MAAM,IAAI,aAAa,CACrB,qBAAqB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,0BAA0B,OAAO,KAAK;YAC9E,2CAA2C,mBAAmB,GAAG,CACpE,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,sGAAsG;AACtG,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,IAAY,EAAE,KAAoB;IACzE,MAAM,IAAI,aAAa,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,kBAAkB,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;AAC1E,CAAC"}
@@ -0,0 +1,24 @@
1
+ import type { ProbeOutcome } from '../detection/squadronProbe.js';
2
+ /** The context profile / prompt instruction selected for a brownfield build. */
3
+ export declare const BROWNFIELD_ADOPTION_INSTRUCTION = "brownfield-adoption";
4
+ /** Runs the squadron capability probe in a checkout; injected so tests never spawn `sq`. */
5
+ export type SquadronProbe = (checkoutPath: string) => Promise<ProbeOutcome>;
6
+ export type AdoptionSelection = {
7
+ selected: false;
8
+ } | {
9
+ selected: true;
10
+ instruction: typeof BROWNFIELD_ADOPTION_INSTRUCTION;
11
+ facts: string;
12
+ /** Newest squadron comprehension document, relative to project-documents/. Absent when none. */
13
+ fileComprehension?: string;
14
+ };
15
+ export type AdoptionResolver = (projectPath: string, checkoutPath: string, instruction: string) => Promise<AdoptionSelection>;
16
+ /**
17
+ * Raised when adoption cannot be decided or applied (guide without the profile or
18
+ * prompt, failed state write, unfinishable walk). The message carries the remedy.
19
+ * The build rethrows it instead of falling back to the concept prompt.
20
+ */
21
+ export declare class AdoptionError extends Error {
22
+ constructor(message: string, options?: ErrorOptions);
23
+ }
24
+ //# sourceMappingURL=contracts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../../src/adoption/contracts.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAElE,gFAAgF;AAChF,eAAO,MAAM,+BAA+B,wBAAwB,CAAC;AAErE,4FAA4F;AAC5F,MAAM,MAAM,aAAa,GAAG,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;AAE5E,MAAM,MAAM,iBAAiB,GACzB;IAAE,QAAQ,EAAE,KAAK,CAAA;CAAE,GACnB;IACE,QAAQ,EAAE,IAAI,CAAC;IACf,WAAW,EAAE,OAAO,+BAA+B,CAAC;IACpD,KAAK,EAAE,MAAM,CAAC;IACd,gGAAgG;IAChG,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEN,MAAM,MAAM,gBAAgB,GAAG,CAC7B,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,KAChB,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAEhC;;;;GAIG;AACH,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIpD"}
@@ -0,0 +1,14 @@
1
+ /** The context profile / prompt instruction selected for a brownfield build. */
2
+ export const BROWNFIELD_ADOPTION_INSTRUCTION = 'brownfield-adoption';
3
+ /**
4
+ * Raised when adoption cannot be decided or applied (guide without the profile or
5
+ * prompt, failed state write, unfinishable walk). The message carries the remedy.
6
+ * The build rethrows it instead of falling back to the concept prompt.
7
+ */
8
+ export class AdoptionError extends Error {
9
+ constructor(message, options) {
10
+ super(message, options);
11
+ this.name = 'AdoptionError';
12
+ }
13
+ }
14
+ //# sourceMappingURL=contracts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contracts.js","sourceRoot":"","sources":["../../src/adoption/contracts.ts"],"names":[],"mappings":"AAKA,gFAAgF;AAChF,MAAM,CAAC,MAAM,+BAA+B,GAAG,qBAAqB,CAAC;AAqBrE;;;;GAIG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC,YAAY,OAAe,EAAE,OAAsB;QACjD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF"}
@@ -0,0 +1,7 @@
1
+ export * from './contracts.js';
2
+ export * from './adoptionState.js';
3
+ export * from './adoptionOutcome.js';
4
+ export * from './adoptionFacts.js';
5
+ export * from './adoptionResolver.js';
6
+ export * from './adoptionCompletion.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adoption/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC"}
@@ -0,0 +1,7 @@
1
+ export * from './contracts.js';
2
+ export * from './adoptionState.js';
3
+ export * from './adoptionOutcome.js';
4
+ export * from './adoptionFacts.js';
5
+ export * from './adoptionResolver.js';
6
+ export * from './adoptionCompletion.js';
7
+ //# sourceMappingURL=index.js.map