spell 0.8.7 → 0.8.8

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 (243) hide show
  1. package/README-epics.md +96 -36
  2. package/app/package.json +25 -1
  3. package/dist/cli/publish/PublishedPackage.d.ts +2 -1
  4. package/dist/cli/publish/PublishedPackage.js +6 -3
  5. package/dist/cli/publish/ScratchInstall.d.ts +14 -3
  6. package/dist/cli/publish/ScratchInstall.js +69 -8
  7. package/dist/epic/cli/EpicProgram.js +7 -1
  8. package/dist/epic/cli/epicGroups.js +2 -1
  9. package/dist/epic/command/BaseBranch.d.ts +35 -0
  10. package/dist/epic/command/BaseBranch.js +58 -0
  11. package/dist/epic/command/EpicCheckout.d.ts +1 -1
  12. package/dist/epic/command/EpicCheckout.js +4 -4
  13. package/dist/epic/command/EpicGuide.js +3 -2
  14. package/dist/epic/command/EpicTools.d.ts +5 -0
  15. package/dist/epic/command/EpicTools.js +14 -3
  16. package/dist/epic/command/MainMerge.d.ts +26 -15
  17. package/dist/epic/command/MainMerge.js +60 -16
  18. package/dist/epic/command/RepoInit.d.ts +116 -8
  19. package/dist/epic/command/RepoInit.js +308 -13
  20. package/dist/epic/command/Requests.d.ts +1 -0
  21. package/dist/epic/command/Requests.js +6 -1
  22. package/dist/epic/command/SessionMoves.js +2 -1
  23. package/dist/epic/command/SkillsCheck.js +3 -2
  24. package/dist/epic/command/Stock.js +3 -1
  25. package/dist/epic/command/TurnEnd.d.ts +1 -1
  26. package/dist/epic/command/TurnEnd.js +4 -3
  27. package/dist/epic/command/Worktrees.d.ts +18 -3
  28. package/dist/epic/command/Worktrees.js +38 -7
  29. package/dist/epic/command/command.types.d.ts +3 -0
  30. package/dist/epic/components/__pack/epics.entry.js +43 -43
  31. package/dist/epic/components/__pack/epics.pack.js +36 -12794
  32. package/dist/epic/config/EngineFiles.mjs +60 -0
  33. package/dist/epic/config/EpicConfig.d.ts +12 -2
  34. package/dist/epic/config/EpicConfig.js +9 -1
  35. package/dist/epic/config/GitHub.d.ts +41 -1
  36. package/dist/epic/config/GitHub.js +75 -3
  37. package/dist/epic/config/LayeredSettings.js +3 -2
  38. package/dist/epic/server/EpicServer.d.ts +1 -1
  39. package/dist/epic/server/EpicServer.js +26 -12
  40. package/dist/epic/tool/InboxPoller.mjs +2 -1
  41. package/dist/epic/tool/MigrateCommands.js +6 -8
  42. package/dist/epic/tool/PlanDocFiles.js +3 -2
  43. package/dist/epic/tool/ServedFolders.d.ts +1 -1
  44. package/dist/epic/tool/ServedFolders.js +4 -4
  45. package/dist/epic/tools/PageInboxes.js +3 -3
  46. package/dist/epic/tools/_assets/commands.entry.js +149 -68
  47. package/dist/epic/tools/_assets/commands.js +20 -2073
  48. package/dist/epic/tools/_assets/core-reference.entry.js +244 -124
  49. package/dist/epic/tools/_assets/core-reference.js +20 -2142
  50. package/dist/epic/tools/_assets/emoji/cldr/0.js +2 -2
  51. package/dist/epic/tools/_assets/emoji/cldr/a.js +2 -2
  52. package/dist/epic/tools/_assets/emoji/cldr/b.js +2 -2
  53. package/dist/epic/tools/_assets/emoji/cldr/c.js +2 -2
  54. package/dist/epic/tools/_assets/emoji/cldr/d.js +2 -2
  55. package/dist/epic/tools/_assets/emoji/cldr/e.js +2 -2
  56. package/dist/epic/tools/_assets/emoji/cldr/f.js +2 -2
  57. package/dist/epic/tools/_assets/emoji/cldr/g.js +2 -2
  58. package/dist/epic/tools/_assets/emoji/cldr/h.js +2 -2
  59. package/dist/epic/tools/_assets/emoji/cldr/i.js +2 -2
  60. package/dist/epic/tools/_assets/emoji/cldr/j.js +2 -2
  61. package/dist/epic/tools/_assets/emoji/cldr/k.js +2 -2
  62. package/dist/epic/tools/_assets/emoji/cldr/l.js +2 -2
  63. package/dist/epic/tools/_assets/emoji/cldr/m.js +2 -2
  64. package/dist/epic/tools/_assets/emoji/cldr/n.js +2 -2
  65. package/dist/epic/tools/_assets/emoji/cldr/o.js +2 -2
  66. package/dist/epic/tools/_assets/emoji/cldr/p.js +2 -2
  67. package/dist/epic/tools/_assets/emoji/cldr/r.js +2 -2
  68. package/dist/epic/tools/_assets/emoji/cldr/s.js +2 -2
  69. package/dist/epic/tools/_assets/emoji/cldr/t.js +2 -2
  70. package/dist/epic/tools/_assets/emoji/cldr/u.js +2 -2
  71. package/dist/epic/tools/_assets/emoji/cldr/v.js +2 -2
  72. package/dist/epic/tools/_assets/emoji/cldr/w.js +2 -2
  73. package/dist/epic/tools/_assets/emoji/cldr/x.js +2 -2
  74. package/dist/epic/tools/_assets/emoji/cldr/y.js +2 -2
  75. package/dist/epic/tools/_assets/emoji/cldr/z.js +2 -2
  76. package/dist/epic/tools/_assets/emoji/fomantic/0.js +2 -2
  77. package/dist/epic/tools/_assets/emoji/fomantic/a.js +2 -2
  78. package/dist/epic/tools/_assets/emoji/fomantic/b.js +2 -2
  79. package/dist/epic/tools/_assets/emoji/fomantic/c.js +2 -2
  80. package/dist/epic/tools/_assets/emoji/fomantic/d.js +2 -2
  81. package/dist/epic/tools/_assets/emoji/fomantic/e.js +2 -2
  82. package/dist/epic/tools/_assets/emoji/fomantic/f.js +2 -2
  83. package/dist/epic/tools/_assets/emoji/fomantic/g.js +2 -2
  84. package/dist/epic/tools/_assets/emoji/fomantic/h.js +2 -2
  85. package/dist/epic/tools/_assets/emoji/fomantic/i.js +2 -2
  86. package/dist/epic/tools/_assets/emoji/fomantic/j.js +2 -2
  87. package/dist/epic/tools/_assets/emoji/fomantic/k.js +2 -2
  88. package/dist/epic/tools/_assets/emoji/fomantic/l.js +2 -2
  89. package/dist/epic/tools/_assets/emoji/fomantic/m.js +2 -2
  90. package/dist/epic/tools/_assets/emoji/fomantic/n.js +2 -2
  91. package/dist/epic/tools/_assets/emoji/fomantic/o.js +2 -2
  92. package/dist/epic/tools/_assets/emoji/fomantic/p.js +2 -2
  93. package/dist/epic/tools/_assets/emoji/fomantic/q.js +2 -2
  94. package/dist/epic/tools/_assets/emoji/fomantic/r.js +2 -2
  95. package/dist/epic/tools/_assets/emoji/fomantic/s.js +2 -2
  96. package/dist/epic/tools/_assets/emoji/fomantic/t.js +2 -2
  97. package/dist/epic/tools/_assets/emoji/fomantic/u.js +2 -2
  98. package/dist/epic/tools/_assets/emoji/fomantic/v.js +2 -2
  99. package/dist/epic/tools/_assets/emoji/fomantic/w.js +2 -2
  100. package/dist/epic/tools/_assets/emoji/fomantic/x.js +2 -2
  101. package/dist/epic/tools/_assets/emoji/fomantic/y.js +2 -2
  102. package/dist/epic/tools/_assets/emoji/fomantic/z.js +2 -2
  103. package/dist/epic/tools/_assets/goals-live.js +318 -210
  104. package/dist/epic/tools/_assets/highlight.min.js +5764 -5269
  105. package/dist/epic/tools/_assets/lazy/code-engine.js +5 -1270
  106. package/dist/epic/tools/_assets/lazy/markdown-engine.js +67 -1513
  107. package/dist/epic/tools/_assets/lazy/markdown-sanitizer.js +3 -753
  108. package/dist/epic/tools/_assets/spell-comments.entry.js +282 -159
  109. package/dist/epic/tools/_assets/spell-comments.js +24 -3716
  110. package/dist/epic/tools/_assets/spell-doc-comments.js +1243 -816
  111. package/dist/epic/tools/_assets/spell-doc-helpers.js +298 -165
  112. package/dist/epic/tools/_assets/spell-doc-runtime.js +2760 -1415
  113. package/dist/epic/tools/_assets/spell-doc-toolbar.js +396 -227
  114. package/dist/epic/tools/_assets/spell-syntax.entry.js +505 -285
  115. package/dist/epic/tools/_assets/spell-syntax.js +22 -2916
  116. package/dist/epic/tools/_assets/spell-ui-sources.js +102 -60
  117. package/dist/epic/tools/_assets/spell-ui.entry.js +108 -40
  118. package/dist/epic/tools/_assets/spell-ui.js +3131 -46465
  119. package/dist/epic/tools/pages.d.ts +5 -6
  120. package/dist/epic/tools/pages.js +7 -6
  121. package/dist/epic/window.mjs +2 -3
  122. package/dist/ui/components/ui-accordion/UIAccordion.d.ts +1 -0
  123. package/dist/ui/components/ui-ad/UIAd.d.ts +1 -0
  124. package/dist/ui/components/ui-breadcrumbs/UIBreadcrumb.d.ts +1 -0
  125. package/dist/ui/components/ui-breadcrumbs/UIBreadcrumbs.d.ts +1 -0
  126. package/dist/ui/components/ui-button/UIButton.d.ts +8 -3
  127. package/dist/ui/components/ui-button/UIButton.fallback.d.ts +8 -3
  128. package/dist/ui/components/ui-button/UIButtons.d.ts +1 -0
  129. package/dist/ui/components/ui-button/UIOr.d.ts +1 -0
  130. package/dist/ui/components/ui-calendar/UICalendar.d.ts +6 -0
  131. package/dist/ui/components/ui-calendar/UICalendar.fallback.d.ts +6 -0
  132. package/dist/ui/components/ui-card/UICards.d.ts +31 -0
  133. package/dist/ui/components/ui-checkbox/UICheckbox.d.ts +7 -0
  134. package/dist/ui/components/ui-checkbox/UICheckbox.fallback.d.ts +7 -0
  135. package/dist/ui/components/ui-comment/UIComment.d.ts +1 -0
  136. package/dist/ui/components/ui-comment/UIComments.d.ts +1 -0
  137. package/dist/ui/components/ui-components/UIComponents.d.ts +1 -0
  138. package/dist/ui/components/ui-dimmer/UIDimmer.d.ts +1 -0
  139. package/dist/ui/components/ui-divider/UIDivider.d.ts +2 -0
  140. package/dist/ui/components/ui-dropdown/UIDropdown.d.ts +6 -0
  141. package/dist/ui/components/ui-dropdown/UIDropdown.fallback.d.ts +6 -0
  142. package/dist/ui/components/ui-embed/UIEmbed.d.ts +1 -0
  143. package/dist/ui/components/ui-emoji/UIEmoji.d.ts +1 -0
  144. package/dist/ui/components/ui-feed/UIFeed.d.ts +1 -0
  145. package/dist/ui/components/ui-feed/UIFeedEvent.d.ts +1 -0
  146. package/dist/ui/components/ui-flag/UIFlag.d.ts +1 -0
  147. package/dist/ui/components/ui-flyout/UIFlyout.d.ts +1 -0
  148. package/dist/ui/components/ui-form/UIFields.d.ts +1 -0
  149. package/dist/ui/components/ui-form/UIRepeat.d.ts +1 -0
  150. package/dist/ui/components/ui-grid/UIColumn.d.ts +1 -0
  151. package/dist/ui/components/ui-grid/UIGrid.d.ts +1 -0
  152. package/dist/ui/components/ui-grid/UIRow.d.ts +1 -0
  153. package/dist/ui/components/ui-icon/UIIcon.d.ts +3 -2
  154. package/dist/ui/components/ui-icon/UIIcons.d.ts +1 -0
  155. package/dist/ui/components/ui-icon-picker/UIIconPicker.d.ts +6 -0
  156. package/dist/ui/components/ui-icon-picker/UIIconPicker.fallback.d.ts +6 -0
  157. package/dist/ui/components/ui-image/UIImages.d.ts +1 -0
  158. package/dist/ui/components/ui-include/UIInclude.d.ts +1 -0
  159. package/dist/ui/components/ui-input/UIInput.fallback.d.ts +9 -2
  160. package/dist/ui/components/ui-items/UIItems.d.ts +1 -0
  161. package/dist/ui/components/ui-keys/UIKeys.d.ts +1 -0
  162. package/dist/ui/components/ui-label/UILabel.d.ts +2 -0
  163. package/dist/ui/components/ui-label/UILabels.d.ts +1 -0
  164. package/dist/ui/components/ui-list/UIList.d.ts +2 -0
  165. package/dist/ui/components/ui-loader/UILoader.d.ts +1 -0
  166. package/dist/ui/components/ui-message/UIMessage.d.ts +2 -0
  167. package/dist/ui/components/ui-modal/UIModal.d.ts +1 -0
  168. package/dist/ui/components/ui-nag/UINag.d.ts +1 -0
  169. package/dist/ui/components/ui-page/UIPage.d.ts +15 -0
  170. package/dist/ui/components/ui-page/UIPage.es.d.ts +1 -0
  171. package/dist/ui/components/ui-parts/UIActions.d.ts +1 -0
  172. package/dist/ui/components/ui-parts/UIAuthor.d.ts +1 -0
  173. package/dist/ui/components/ui-parts/UIAvatar.d.ts +1 -0
  174. package/dist/ui/components/ui-parts/UIContent.d.ts +1 -0
  175. package/dist/ui/components/ui-parts/UIDate.d.ts +1 -0
  176. package/dist/ui/components/ui-parts/UIDescription.d.ts +1 -0
  177. package/dist/ui/components/ui-parts/UIDetail.d.ts +1 -0
  178. package/dist/ui/components/ui-parts/UIExtra.d.ts +1 -0
  179. package/dist/ui/components/ui-parts/UIHeader.d.ts +3 -1
  180. package/dist/ui/components/ui-parts/UIMeta.d.ts +1 -0
  181. package/dist/ui/components/ui-parts/UIParts.types.d.ts +15 -1
  182. package/dist/ui/components/ui-parts/UISummary.d.ts +1 -0
  183. package/dist/ui/components/ui-parts/UITitle.d.ts +1 -0
  184. package/dist/ui/components/ui-parts/UIValue.d.ts +1 -0
  185. package/dist/ui/components/ui-placeholder/UIPlaceholder.d.ts +1 -0
  186. package/dist/ui/components/ui-placeholder/UIPlaceholderHeader.d.ts +1 -0
  187. package/dist/ui/components/ui-placeholder/UIPlaceholderImage.d.ts +1 -0
  188. package/dist/ui/components/ui-placeholder/UIPlaceholderLine.d.ts +1 -0
  189. package/dist/ui/components/ui-placeholder/UIPlaceholderParagraph.d.ts +1 -0
  190. package/dist/ui/components/ui-progress/UIProgress.d.ts +2 -0
  191. package/dist/ui/components/ui-quote/UIQuote.d.ts +1 -0
  192. package/dist/ui/components/ui-rail/UIRail.d.ts +1 -0
  193. package/dist/ui/components/ui-rating/UIRating.d.ts +6 -0
  194. package/dist/ui/components/ui-rating/UIRating.fallback.d.ts +6 -0
  195. package/dist/ui/components/ui-reveal/UIReveal.d.ts +1 -0
  196. package/dist/ui/components/ui-search/UISearch.fallback.d.ts +13 -1
  197. package/dist/ui/components/ui-section/UISections.d.ts +1 -0
  198. package/dist/ui/components/ui-segment/UISegment.d.ts +2 -0
  199. package/dist/ui/components/ui-segment/UISegments.d.ts +1 -0
  200. package/dist/ui/components/ui-select/UISelect.d.ts +6 -0
  201. package/dist/ui/components/ui-select/UISelect.fallback.d.ts +6 -0
  202. package/dist/ui/components/ui-shape/UISide.d.ts +4 -0
  203. package/dist/ui/components/ui-sidebar/UIPushable.d.ts +1 -0
  204. package/dist/ui/components/ui-sidebar/UIPusher.d.ts +1 -0
  205. package/dist/ui/components/ui-sidebar/UISidebar.d.ts +1 -0
  206. package/dist/ui/components/ui-sides/UISides.d.ts +6 -0
  207. package/dist/ui/components/ui-sides/UISides.fallback.d.ts +6 -0
  208. package/dist/ui/components/ui-slider/UISlider.d.ts +7 -0
  209. package/dist/ui/components/ui-slider/UISlider.fallback.d.ts +7 -0
  210. package/dist/ui/components/ui-space/UISpace.d.ts +1 -0
  211. package/dist/ui/components/ui-statistic/UIStatistic.d.ts +1 -0
  212. package/dist/ui/components/ui-statistic/UIStatistics.d.ts +1 -0
  213. package/dist/ui/components/ui-step/UIStep.d.ts +1 -0
  214. package/dist/ui/components/ui-step/UISteps.d.ts +1 -0
  215. package/dist/ui/components/ui-table/UICell.d.ts +1 -0
  216. package/dist/ui/components/ui-terms/UITerm.d.ts +1 -0
  217. package/dist/ui/components/ui-terms/UITerms.d.ts +1 -0
  218. package/dist/ui/components/ui-theme-editor/UIColorChip.d.ts +1 -0
  219. package/dist/ui/components/ui-theme-editor/UIThemeToken.d.ts +1 -0
  220. package/dist/ui/components/ui-toast/UIToast.d.ts +1 -0
  221. package/dist/ui/components/ui-toc/UIToc.d.ts +1 -0
  222. package/dist/ui/components/ui-transition/UITransition.d.ts +1 -0
  223. package/dist/ui/components/ui-video/UIAudio.d.ts +1 -0
  224. package/dist/ui/components/ui-video/UIVideo.d.ts +1 -0
  225. package/dist/ui/components/ui-visibility/UIVisibility.d.ts +1 -0
  226. package/dist/ui/components/ui-zoom/UIZoom.d.ts +1 -0
  227. package/dist/util/spell/constants.js +1 -1
  228. package/epic/.claude-plugin/plugin.json +1 -1
  229. package/epic/.codex-plugin/plugin.json +1 -1
  230. package/epic/hooks/handoff.mjs +4 -3
  231. package/epic/hooks/worktree.mjs +22 -3
  232. package/epic/package.json +41 -2
  233. package/epic/skills/details/SKILL.md +2 -1
  234. package/epic/skills/epic/SKILL.md +7 -1
  235. package/epic/skills/epic/guide.md +4 -0
  236. package/epic/skills/isolate/SKILL.md +35 -0
  237. package/epic/src/AGENTS.md +6 -2
  238. package/epic/templates/durable.html +1 -1
  239. package/epic/vscode/package.json +1 -1
  240. package/epic/vscode/spell-epic.vsix +0 -0
  241. package/package.json +1 -1
  242. package/parser/package.json +1 -1
  243. package/ui/package.json +15 -2
@@ -2,7 +2,17 @@ var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
4
  // src/command/RepoInit.ts
5
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
5
+ import {
6
+ appendFileSync,
7
+ existsSync,
8
+ mkdirSync,
9
+ mkdtempSync,
10
+ readFileSync,
11
+ rmSync,
12
+ rmdirSync,
13
+ writeFileSync
14
+ } from "node:fs";
15
+ import { tmpdir } from "node:os";
6
16
  import { basename, dirname, join, relative } from "node:path";
7
17
  import chalk from "chalk";
8
18
  import { DataFile } from "spell/server/DataFile";
@@ -39,7 +49,16 @@ var RepoInit = class _RepoInit {
39
49
  }
40
50
  /** Run `epic init <args>`; resolves to the exit code. Throws `EpicCommandError` outside a git repo. */
41
51
  async run(args) {
42
- const { flags } = parseVerbArgs(args, ["dryRun", "json", "noRemote", "public", "noPlugin", "noServer", "noCommit"]);
52
+ const { flags } = parseVerbArgs(args, [
53
+ "dryRun",
54
+ "json",
55
+ "noRemote",
56
+ "public",
57
+ "noPlugin",
58
+ "noServer",
59
+ "noCommit",
60
+ "protectedBase"
61
+ ]);
43
62
  const dryRun = flags.dryRun === true;
44
63
  const remote = stringFlag(flags.remote);
45
64
  const contentRepo = stringFlag(flags.contentRepo);
@@ -85,16 +104,23 @@ var RepoInit = class _RepoInit {
85
104
  noRemote,
86
105
  color: answers.color,
87
106
  cloned: answers.cloned,
107
+ protectedBase: flags.protectedBase === true,
88
108
  say
89
109
  });
90
110
  if (plugin) report.plugin = plugin;
91
111
  print([..._RepoInit.fileLines(report, { head: false }), ..._RepoInit.noteLines(report)]);
92
112
  if (flags.noCommit !== true && report.content.action !== "missing") {
93
- if (_RepoInit.changedFiles(report).length) print(["", chalk.bold(COMMIT_HEADER)]);
113
+ if (_RepoInit.changedFiles(report).length) print(["", chalk.bold(_RepoInit.commitHeader(report))]);
94
114
  report.commit = await _RepoInit.commitStep({ report, ask, say });
95
115
  print(_RepoInit.commitResultLines(report.commit));
116
+ } else if (flags.noCommit === true && report.config.settings.baseBranchProtected) {
117
+ const files = _RepoInit.changedFiles(report);
118
+ if (files.length)
119
+ print([
120
+ `> Not committed (--no-commit): ${report.config.settings.baseBranch} takes only pull requests, so put ${files.join(" and ")} on a branch and open one`
121
+ ]);
96
122
  }
97
- if (flags.noServer !== true && report.content.action !== "missing") {
123
+ if (flags.noServer !== true && report.content.action !== "missing" && report.commit?.action !== "on branch") {
98
124
  if (!dryRun) say("starting the epic server…");
99
125
  report.server = await this.serverStep({ dryRun });
100
126
  }
@@ -192,6 +218,7 @@ var RepoInit = class _RepoInit {
192
218
  server = false,
193
219
  commit = false,
194
220
  cloned = false,
221
+ protectedBase = false,
195
222
  say = /* @__PURE__ */ __name(() => {
196
223
  }, "say")
197
224
  } = {}) {
@@ -199,11 +226,15 @@ var RepoInit = class _RepoInit {
199
226
  const pluginReport = plugin ? this.pluginStep({ dryRun }) : void 0;
200
227
  const configFile = join(main, EpicConfig.FILE);
201
228
  const hadConfig = existsSync(configFile);
202
- const settings = hadConfig ? new EpicConfig(main).settings : EpicConfig.defaultsFor(main);
229
+ const found = hadConfig ? new EpicConfig(main).settings : EpicConfig.defaultsFor(main);
230
+ const protection = _RepoInit.protectionStep({ main, configFile, hadConfig, settings: found, protectedBase });
231
+ const settings = { ...found, baseBranchProtected: protection.on };
203
232
  if (!hadConfig && !dryRun) {
204
233
  mkdirSync(dirname(configFile), { recursive: true });
205
234
  writeFileSync(configFile, _RepoInit.configText(settings));
206
235
  }
236
+ if (hadConfig && !dryRun && (protection.action === "flag" || protection.action === "detected"))
237
+ _RepoInit.keepProtected(configFile);
207
238
  const content = join(main, settings.contentFolder);
208
239
  const folders = settings.sharedFolders;
209
240
  const report = {
@@ -214,6 +245,7 @@ var RepoInit = class _RepoInit {
214
245
  links: [],
215
246
  remote: { action: "skipped" },
216
247
  gitignore: { file: join(main, ".gitignore"), action: "ok" },
248
+ protection,
217
249
  person: _RepoInit.personStep({ dryRun, name }),
218
250
  ...pluginReport && { plugin: pluginReport }
219
251
  };
@@ -295,6 +327,7 @@ var RepoInit = class _RepoInit {
295
327
  * - only those files, whatever else is staged (`git commit -- <files>`); none changed: `none`
296
328
  * - on another branch: `other branch`, nothing committed (a worktree branches from the base branch)
297
329
  * - pushed (`pushBranch()`): to the branch's upstream, else `origin`; neither: committed, nothing to push to
330
+ * - a base branch that takes only pull requests: `commitViaPullRequest()` instead, NEVER a commit on it
298
331
  * - NEVER throws: a failed commit is `failed`, a failed push `push: "failed"`, with git's words
299
332
  * - SIDE EFFECT (not `dryRun`): a commit in the repo, a push
300
333
  */
@@ -304,6 +337,7 @@ var RepoInit = class _RepoInit {
304
337
  say = /* @__PURE__ */ __name(() => {
305
338
  }, "say")
306
339
  }) {
340
+ if (report.config.settings.baseBranchProtected) return _RepoInit.commitViaPullRequest({ report, ask, say });
307
341
  const { main, dryRun } = report;
308
342
  const base = report.config.settings.baseBranch;
309
343
  const files = _RepoInit.changedFiles(report);
@@ -320,9 +354,197 @@ var RepoInit = class _RepoInit {
320
354
  if (!done.ok) return { action: "failed", files, branch, error: done.err || `git exited ${done.code}` };
321
355
  return { action: "committed", files, branch, ..._RepoInit.pushBranch(main, branch, say) };
322
356
  }
323
- /** The files `epic init` changed in the repo, still to commit: the config, `.gitignore`. */
324
- static changedFiles({ main }) {
325
- return [EpicConfig.FILE, ".gitignore"].filter((file) => Git.out(["status", "--porcelain", "--", file], main));
357
+ /**
358
+ * The files `epic init` wrote, for a base branch that takes only pull requests: committed on a new branch
359
+ * (`SETUP_BRANCH`) WITHOUT touching the base branch, pushed, a pull request opened; what it did.
360
+ * - asks first in a terminal, `y` suggested; with no terminal, yes
361
+ * - on another branch: `other branch`, nothing done
362
+ * - a commit of `epic init`'s own on the base branch, not pushed (a run before this setting was on, its push refused):
363
+ * taken back first, keeping its files (`undoOwnCommit()`)
364
+ * - the branch is made without checking it out (`commitOnSetupBranch()`), then the base branch's checkout put back as
365
+ * it was (`restoreBase()`): so "safe to run again", whatever else is staged or changed
366
+ * - the pull request: `gh pr create` when `gh` is logged in; else `pullRequestError` says why, and the lines say what
367
+ * to run
368
+ * - NEVER throws
369
+ * - SIDE EFFECT (not `dryRun`): a branch, a push, a pull request, the two files out of the checkout
370
+ */
371
+ static async commitViaPullRequest({
372
+ report,
373
+ ask,
374
+ say = /* @__PURE__ */ __name(() => {
375
+ }, "say")
376
+ }) {
377
+ const { main, dryRun } = report;
378
+ const base = report.config.settings.baseBranch;
379
+ const via = { viaPullRequest: true, base };
380
+ const branch = Git.out(["rev-parse", "--abbrev-ref", "HEAD"], main) ?? "";
381
+ if (!dryRun && branch === base) _RepoInit.undoOwnCommit(main, base);
382
+ const files = _RepoInit.changedFiles(report);
383
+ if (!files.length) return { action: "none", files, branch: base, ...via };
384
+ if (branch !== base) return { action: "other branch", files, branch, ...via };
385
+ if (dryRun) return { action: "would branch", files, branch: SETUP_BRANCH, ...via };
386
+ const question = `Put ${files.join(" and ")} on a new branch ${SETUP_BRANCH}, push it, and open a pull request?`;
387
+ const answer = ask ? await CLI.ask(question, { suggestion: "y" }) : "y";
388
+ if (/^n/i.test(answer.trim())) return { action: "declined", files, branch, ...via };
389
+ try {
390
+ _RepoInit.commitOnSetupBranch(main, base, files);
391
+ _RepoInit.restoreBase(main, files, report.config.settings.sharedFolders);
392
+ } catch (error) {
393
+ return { action: "failed", files, branch: SETUP_BRANCH, error: error.message, ...via };
394
+ }
395
+ const pushed = _RepoInit.pushBranch(main, SETUP_BRANCH, say);
396
+ const done = { action: "on branch", files, branch: SETUP_BRANCH, ...via, ...pushed };
397
+ return pushed.push === "pushed" ? { ...done, ..._RepoInit.pullRequestStep(main, base, say) } : done;
398
+ }
399
+ /**
400
+ * Take back `epic init`'s own commit from base branch `base`, when it's its last commit and the only one `origin`'s
401
+ * lacks: an earlier run's, its push refused. Its files stay, uncommitted.
402
+ * - anything else on the branch that `origin`'s lacks: left alone
403
+ * - SIDE EFFECT: `git reset --mixed HEAD~1`
404
+ */
405
+ static undoOwnCommit(main, base) {
406
+ if (Git.out(["rev-list", "--count", `refs/remotes/origin/${base}..${base}`], main) !== "1") return;
407
+ if (Git.out(["log", "-1", "--format=%s", base], main) !== COMMIT_MESSAGE) return;
408
+ Git.run(["reset", "-q", "--mixed", "HEAD~1"], main);
409
+ }
410
+ /**
411
+ * `files`, as they are on disk, committed on `SETUP_BRANCH`: with a temporary index, so HEAD, the checkout's own
412
+ * index and any other change there are never touched.
413
+ * - from `base`, or on top of the branch when it holds work `base` doesn't (a run before, its pull request open)
414
+ * - nothing new to commit: the branch stays
415
+ * - throws a `GitError` when git can't
416
+ * - SIDE EFFECT: a commit, and the branch made or moved
417
+ */
418
+ static commitOnSetupBranch(main, base, files) {
419
+ const tip = Git.out(["rev-parse", "--verify", "--quiet", `refs/heads/${SETUP_BRANCH}`], main);
420
+ const parent = tip && !Git.run(["merge-base", "--is-ancestor", tip, base], main).ok ? tip : Git.mustRun(["rev-parse", base], main);
421
+ const folder = mkdtempSync(join(tmpdir(), "epic-setup-"));
422
+ const env = { ...process.env, GIT_INDEX_FILE: join(folder, "index") };
423
+ try {
424
+ Git.mustRun(["read-tree", parent], main, { env });
425
+ for (const file of files) {
426
+ const blob = Git.mustRun(["hash-object", "-w", "--", file], main);
427
+ Git.mustRun(["update-index", "--add", "--cacheinfo", `100644,${blob},${file}`], main, { env });
428
+ }
429
+ const tree = Git.mustRun(["write-tree"], main, { env });
430
+ if (tree === Git.out(["rev-parse", `${parent}^{tree}`], main)) return;
431
+ const commit = Git.mustRun(["commit-tree", tree, "-p", parent, "-m", COMMIT_MESSAGE], main);
432
+ Git.mustRun(["update-ref", `refs/heads/${SETUP_BRANCH}`, commit], main);
433
+ } finally {
434
+ rmSync(folder, { recursive: true, force: true });
435
+ }
436
+ }
437
+ /**
438
+ * Put the base branch's checkout back: `files` as HEAD has them, or gone when it hasn't any, so `git status` is clean.
439
+ * - the links `init()` made (`links`) are listed in `.git/info/exclude`: the `.gitignore` that names them is on the
440
+ * setup branch until it's merged
441
+ * - throws a `GitError` when git can't
442
+ * - SIDE EFFECT: the two files, the exclude file
443
+ */
444
+ static restoreBase(main, files, links) {
445
+ for (const file of files) {
446
+ if (Git.run(["cat-file", "-e", `HEAD:${file}`], main).ok) Git.mustRun(["checkout", "HEAD", "--", file], main);
447
+ else {
448
+ Git.run(["rm", "-q", "--cached", "--ignore-unmatch", "--", file], main);
449
+ rmSync(join(main, file), { force: true });
450
+ }
451
+ }
452
+ try {
453
+ rmdirSync(join(main, dirname(EpicConfig.FILE)));
454
+ } catch {
455
+ }
456
+ const exclude = join(main, ".git", "info", "exclude");
457
+ const listed = existsSync(exclude) ? readFileSync(exclude, "utf8").split("\n") : [];
458
+ const missing = links.map((link) => `/${link}`).filter((line) => !listed.includes(line));
459
+ if (!missing.length) return;
460
+ mkdirSync(dirname(exclude), { recursive: true });
461
+ appendFileSync(exclude, `${EXCLUDE_NOTE}
462
+ ${missing.join("\n")}
463
+ `);
464
+ }
465
+ /**
466
+ * The pull request for `SETUP_BRANCH`, opened with `gh`: its address, or why not.
467
+ * - NEVER throws
468
+ * - SIDE EFFECT: a pull request on GitHub
469
+ */
470
+ static pullRequestStep(main, base, say) {
471
+ const status = GitHub.status();
472
+ if (status === "missing") return { pullRequestError: "GitHub's command, gh, isn't installed" };
473
+ if (status === "logged-out") return { pullRequestError: "gh isn't logged in to GitHub" };
474
+ say("opening the pull request…");
475
+ try {
476
+ return {
477
+ pullRequest: GitHub.openPullRequest({ branch: SETUP_BRANCH, base, title: PR_TITLE, body: PR_BODY, cwd: main })
478
+ };
479
+ } catch (error) {
480
+ return { pullRequestError: error.message };
481
+ }
482
+ }
483
+ /**
484
+ * Whether the base branch takes only pull requests, and how that's known; what `init()` puts in the config.
485
+ * - already on in the config, or in the setup branch's (run again, its pull request not merged yet): `config`
486
+ * - `protectedBase` (`--protected-base`): `flag`
487
+ * - else GitHub's word (`githubRequiresPullRequest()`): `detected`; no such rule: `off`
488
+ * - a config that says `false` in so many words stays so (a file already there is kept): `says off`, and a note
489
+ * - NEVER throws: failing to find out is `off`, never a failed init
490
+ */
491
+ static protectionStep({
492
+ main,
493
+ configFile,
494
+ hadConfig,
495
+ settings,
496
+ protectedBase
497
+ }) {
498
+ if (settings.baseBranchProtected || _RepoInit.setupBranchSaysProtected(main)) return { action: "config", on: true };
499
+ if (protectedBase) return { action: "flag", on: true };
500
+ try {
501
+ if (!_RepoInit.githubRequiresPullRequest(main, settings.baseBranch)) return { action: "off", on: false };
502
+ const written = hadConfig ? EpicConfig.parse(readFileSync(configFile, "utf8"), configFile) : {};
503
+ return "baseBranchProtected" in written ? { action: "says off", on: false } : { action: "detected", on: true };
504
+ } catch {
505
+ return { action: "off", on: false };
506
+ }
507
+ }
508
+ /** Whether `SETUP_BRANCH`, when there is one, holds a config with `baseBranchProtected` on. */
509
+ static setupBranchSaysProtected(main) {
510
+ const text = Git.out(["show", `refs/heads/${SETUP_BRANCH}:${EpicConfig.FILE}`], main);
511
+ if (!text) return false;
512
+ try {
513
+ return EpicConfig.settingsFrom(text, EpicConfig.FILE, main).baseBranchProtected;
514
+ } catch {
515
+ return false;
516
+ }
517
+ }
518
+ /** Whether GitHub, as `gh` can see it, requires a pull request into `base` of checkout `main`'s `origin`. */
519
+ static githubRequiresPullRequest(main, base) {
520
+ const origin = Git.out(["remote", "get-url", "origin"], main);
521
+ const repo = origin ? GitHub.repoIn(origin) : void 0;
522
+ return repo !== void 0 && GitHub.status() === "ready" && GitHub.requiresPullRequest(repo, base);
523
+ }
524
+ /**
525
+ * Turn `baseBranchProtected` on in config file `file`, keeping the rest as written.
526
+ * - the line `epic init` writes is changed in place; a file without one gets the key through `DataFile`
527
+ * - SIDE EFFECT: writes the file
528
+ */
529
+ static keepProtected(file) {
530
+ const text = readFileSync(file, "utf8");
531
+ const line = /^(\s*"baseBranchProtected":\s*)false/m;
532
+ if (line.test(text)) writeFileSync(file, text.replace(line, "$1true"));
533
+ else DataFile.edit(file, (settings) => ({ ...settings, baseBranchProtected: true }));
534
+ }
535
+ /** What the commit section says first: why `epic init` asks to commit, or to open a pull request. */
536
+ static commitHeader({ config }) {
537
+ return config.settings.baseBranchProtected ? PULL_REQUEST_HEADER : COMMIT_HEADER;
538
+ }
539
+ /**
540
+ * The files `epic init` changed in the repo, still to commit: the config, `.gitignore`.
541
+ * - a dry run wrote nothing: the ones it would have count too
542
+ */
543
+ static changedFiles({ main, dryRun, config, gitignore }) {
544
+ const wouldWrite = /* @__PURE__ */ __name((file) => dryRun && (file === EpicConfig.FILE ? config?.action === "written" : gitignore?.action !== "ok"), "wouldWrite");
545
+ return [EpicConfig.FILE, ".gitignore"].filter(
546
+ (file) => wouldWrite(file) || Git.out(["status", "--porcelain", "--", file], main)
547
+ );
326
548
  }
327
549
  /** Where `branch` of checkout `main` pushes: its upstream (`git push`), else `origin`; none: `undefined`. */
328
550
  static pushTarget(main, branch) {
@@ -602,6 +824,9 @@ var RepoInit = class _RepoInit {
602
824
  "contentRemote": ${value("contentRemote")},
603
825
  // the branch worktrees start from and merge into
604
826
  "baseBranch": ${value("baseBranch")},
827
+ // whether that branch can't be pushed to, and work reaches it only through a pull request:
828
+ // epic init opens one, epic merge refuses, and the skills finish with a pull request
829
+ "baseBranchProtected": ${value("baseBranchProtected")},
605
830
  // where new worktrees go, one folder each: <worktreesFolder>/<name>
606
831
  "worktreesFolder": ${value("worktreesFolder")},
607
832
  // what makes a new worktree ready to run, from its root ("": nothing to install)
@@ -610,7 +835,7 @@ var RepoInit = class _RepoInit {
610
835
  "installOnCreate": ${value("installOnCreate")},
611
836
  // the seconds that install may take
612
837
  "installTimeout": ${value("installTimeout")},
613
- // folders that are yarn projects of their own, outside that install (a \`vscode/\` extension), from a worktree's
838
+ // folders that are projects of their own, outside that install (a \`vscode/\` extension), from a worktree's
614
839
  // root: installCommand runs in each too
615
840
  "extraInstalls": ${value("extraInstalls")},
616
841
  // the VS Code windows: the window file a worktree's window is opened from, the folder names a window shows,
@@ -683,7 +908,7 @@ var RepoInit = class _RepoInit {
683
908
  ...report.plugin ? _RepoInit.pluginLines(report.plugin) : [],
684
909
  ..._RepoInit.fileLines(report),
685
910
  ..._RepoInit.noteLines(report),
686
- ...report.commit?.action && report.commit.action !== "none" ? ["", chalk.bold(COMMIT_HEADER), ..._RepoInit.commitResultLines(report.commit)] : [],
911
+ ...report.commit?.action && report.commit.action !== "none" ? ["", chalk.bold(_RepoInit.commitHeader(report)), ..._RepoInit.commitResultLines(report.commit)] : [],
687
912
  ..._RepoInit.doneLines(report)
688
913
  ];
689
914
  }
@@ -778,19 +1003,27 @@ var RepoInit = class _RepoInit {
778
1003
  }
779
1004
  /** What needs a word of its own, under the files: the epic repo's problems, the colour's, no name. */
780
1005
  static noteLines(report) {
781
- const notes = [...remoteNotesFor(report), ...colorNotesFor(report.color)];
1006
+ const notes = [...protectionNotesFor(report), ...remoteNotesFor(report), ...colorNotesFor(report.color)];
782
1007
  if (report.person.action === "none") notes.push("no name yet (git has no user.name): epic whoami <name> keeps one");
783
1008
  if (!notes.length) return [];
784
1009
  return ["", chalk.bold("Note:"), ...notes];
785
1010
  }
786
1011
  /** What the commit came to (`commitStep()`), under its question. */
787
- static commitResultLines({ action, files, branch, error, push, pushError }) {
1012
+ static commitResultLines(commit) {
1013
+ const { action, files, branch, error, push, pushError } = commit;
788
1014
  const named = files.join(" and ");
1015
+ if (commit.viaPullRequest) return viaPullRequestLines(commit);
789
1016
  switch (action) {
790
1017
  case "committed":
791
1018
  if (push === "pushed") return ["> Committed and pushed"];
792
1019
  if (push === "failed")
793
- return [`> Committed; the push failed: ${pushError}`, ` push it by hand: git push origin ${branch}`];
1020
+ return [
1021
+ `> Committed; the push failed: ${pushError}`,
1022
+ ` push it by hand: git push origin ${branch}`,
1023
+ ...PUSH_REFUSED.test(pushError ?? "") ? [
1024
+ ` or, if ${branch} takes only pull requests: epic init --protected-base (it moves this commit onto a branch, and opens one)`
1025
+ ] : []
1026
+ ];
794
1027
  return ["> Committed; no remote to push to"];
795
1028
  case "would commit":
796
1029
  return [`> would commit ${named} on ${branch}, and push it`];
@@ -811,6 +1044,7 @@ var RepoInit = class _RepoInit {
811
1044
  static doneLines(report) {
812
1045
  if (report.dryRun) return ["", "dry run: nothing changed"];
813
1046
  if (report.content.action === "missing") return [];
1047
+ if (report.commit?.action === "on branch") return ["", chalk.green.bold(DONE_ONCE_MERGED)];
814
1048
  const editor = Editor.of({ setting: report.config.settings.editor });
815
1049
  const { server, main } = report;
816
1050
  const browser = server?.action === "started" && server.address ? terminalLink(server.address) : "epic server start, then the address it prints";
@@ -846,6 +1080,60 @@ function remoteRowsFor({ action, address, repo, visibility, error }) {
846
1080
  }
847
1081
  }
848
1082
  __name(remoteRowsFor, "remoteRowsFor");
1083
+ function protectionNotesFor({ protection, config }) {
1084
+ const base = config.settings.baseBranch;
1085
+ if (protection.action === "detected")
1086
+ return [`GitHub requires a pull request into ${base}: baseBranchProtected is on (${EpicConfig.FILE})`];
1087
+ if (protection.action === "says off")
1088
+ return [
1089
+ `GitHub requires a pull request into ${base}, but ${EpicConfig.FILE} says baseBranchProtected false: epic init --protected-base turns it on`
1090
+ ];
1091
+ return [];
1092
+ }
1093
+ __name(protectionNotesFor, "protectionNotesFor");
1094
+ function viaPullRequestLines(commit) {
1095
+ const { action, files, branch, error, push, pushError, pullRequest, pullRequestError, base } = commit;
1096
+ const named = files.join(" and ");
1097
+ const openIt = [` gh pr create --base ${base} --head ${SETUP_BRANCH} --fill`];
1098
+ const merged = [
1099
+ `> Once it's merged: git pull on ${base}, and epics work here; teammates can join then (epic init in their clone)`
1100
+ ];
1101
+ switch (action) {
1102
+ case "on branch": {
1103
+ const said = [`> ${named} are on branch ${SETUP_BRANCH}; your ${base} is as it was`];
1104
+ if (push === "failed")
1105
+ return [
1106
+ ...said,
1107
+ `> The push failed: ${pushError}`,
1108
+ " to finish:",
1109
+ ` git push -u origin ${SETUP_BRANCH}`,
1110
+ ...openIt,
1111
+ ...merged
1112
+ ];
1113
+ if (push === "nowhere")
1114
+ return [
1115
+ ...said,
1116
+ `> No remote to push to: push ${SETUP_BRANCH} once there is, and open a pull request`,
1117
+ ...merged
1118
+ ];
1119
+ if (pullRequest) return [...said, `> Pull request: ${pullRequest}`, ...merged];
1120
+ return [...said, `> Pushed; no pull request yet (${pullRequestError}). To open one:`, ...openIt, ...merged];
1121
+ }
1122
+ case "would branch":
1123
+ return [
1124
+ `> would put ${named} on a new branch ${SETUP_BRANCH}, push it and open a pull request; ${base} stays as it is`
1125
+ ];
1126
+ case "declined":
1127
+ return [`> Not done: ${base} takes only pull requests, so ${named} need one before epics work here`];
1128
+ case "other branch":
1129
+ return [`> Not done: you're on ${branch}; run epic init on ${base}, which puts ${named} on a new branch`];
1130
+ case "failed":
1131
+ return [`> Couldn't put ${named} on branch ${SETUP_BRANCH}: ${error}`];
1132
+ default:
1133
+ return [];
1134
+ }
1135
+ }
1136
+ __name(viaPullRequestLines, "viaPullRequestLines");
849
1137
  function remoteNotesFor({ remote, content, main }) {
850
1138
  const { address, repo, error, visibility = "private" } = remote;
851
1139
  const pushByHand = [`the push failed: ${error}`, ` push it by hand: git -C ${content.folder} push -u origin HEAD`];
@@ -924,8 +1212,15 @@ var SHOW_README = /* @__PURE__ */ new Set([
924
1212
  ]);
925
1213
  var README_EPICS = "https://github.com/spell-app/spell/blob/main/README-epics.md";
926
1214
  var DONE = "Epics initialized!";
1215
+ var DONE_ONCE_MERGED = "Epics are set up, and start here once that pull request is merged.";
927
1216
  var FILES_HEAD = "Setting up epic files:";
928
1217
  var COMMIT_HEADER = "We need to make a commit in the main repo to enable epics.";
1218
+ var PULL_REQUEST_HEADER = "This repo takes only pull requests into its base branch, so epics are enabled through one.";
1219
+ var SETUP_BRANCH = "epic-setup";
1220
+ var PR_TITLE = "Set up epics";
1221
+ var PR_BODY = "Adds `.epic/config.json5` and the `.gitignore` lines that the `epic` tooling needs, nothing else.\n\nOnce this is merged: `git pull` on the base branch, and teammates can run `epic init`.\n\nThe epic pages live in a repo of their own beside this one, which needs direct pushes: if an org-wide rule requires pull requests, it must leave that repo out.";
1222
+ var EXCLUDE_NOTE = "# epic init: its links, until the pull request that lists them in .gitignore is merged";
1223
+ var PUSH_REFUSED = /rejected|declined|protected|pull request|GH0\d\d/i;
929
1224
  var PUSH_TIMEOUT = 12e4;
930
1225
  var TERMINAL_COLORS = {
931
1226
  red: "#DB2828",
@@ -150,6 +150,7 @@ export declare class Requests {
150
150
  * - moved aside into `ditched` (`StrayFiles.folderFor()`), never deleted, and only once every check passed
151
151
  * - branch `<epic>` holds all of `main`: else `main` moved, and the branch merges it first
152
152
  * (`epic worktree merge-main`, in its worktree)
153
+ * - Refused in one line where `main` takes only pull requests (`baseBranchProtected`).
153
154
  * - Returns the commits it brought onto `main`, oldest first (`[]`: nothing to merge), and what it moved aside.
154
155
  * - throws an `EpicCommandError` saying what to do, for any check that fails: then nothing moved, nothing merged
155
156
  * - static: about the repo `cwd` is in, not the epics folder
@@ -381,6 +381,7 @@ var Requests = class _Requests {
381
381
  * - moved aside into `ditched` (`StrayFiles.folderFor()`), never deleted, and only once every check passed
382
382
  * - branch `<epic>` holds all of `main`: else `main` moved, and the branch merges it first
383
383
  * (`epic worktree merge-main`, in its worktree)
384
+ * - Refused in one line where `main` takes only pull requests (`baseBranchProtected`).
384
385
  * - Returns the commits it brought onto `main`, oldest first (`[]`: nothing to merge), and what it moved aside.
385
386
  * - throws an `EpicCommandError` saying what to do, for any check that fails: then nothing moved, nothing merged
386
387
  * - static: about the repo `cwd` is in, not the epics folder
@@ -402,7 +403,11 @@ ${merged.err}`);
402
403
  * - throws an `EpicCommandError` naming the checkout (`label`) for a check that fails
403
404
  */
404
405
  static mergeCheck(epic, main, { ditch, label }) {
405
- const base = new EpicConfig(main).baseBranch;
406
+ const { baseBranch: base, baseBranchProtected } = new EpicConfig(main);
407
+ if (baseBranchProtected)
408
+ throw new EpicCommandError(
409
+ `merge: ${base} takes only pull requests here (baseBranchProtected): push ${epic} and open one; nothing merged`
410
+ );
406
411
  const branch = Git.run(["branch", "--show-current"], main).out;
407
412
  if (branch !== base) throw new EpicCommandError(`merge: ${label} is on '${branch}', not ${base}`);
408
413
  const stray = new StrayFiles(main);
@@ -15,6 +15,7 @@ import {
15
15
  } from "node:fs";
16
16
  import { basename, dirname, join } from "node:path";
17
17
  import { ClaudeHome } from "../config/ClaudeHome.js";
18
+ import { EngineFiles } from "../config/EngineFiles.mjs";
18
19
  import { EpicHome } from "../config/EpicHome.js";
19
20
  var SessionMoves = class _SessionMoves {
20
21
  static {
@@ -195,7 +196,7 @@ ${missed.message}` : missed.message, "joined");
195
196
  };
196
197
  }
197
198
  };
198
- var ENGINE = dirname(dirname(import.meta.dirname));
199
+ var ENGINE = EngineFiles.root;
199
200
  var PLUGIN = "epic";
200
201
  var MARKETPLACE = "spell";
201
202
  var SESSION_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
@@ -3,8 +3,9 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
3
3
 
4
4
  // src/command/SkillsCheck.ts
5
5
  import { existsSync, readdirSync, readFileSync } from "node:fs";
6
- import { dirname, join } from "node:path";
6
+ import { join } from "node:path";
7
7
  import { CLI } from "spell/cli";
8
+ import { EngineFiles } from "../config/EngineFiles.mjs";
8
9
  import { EXIT, EpicCommandError, parseVerbArgs } from "./command.types.js";
9
10
  var SkillsCheck = class _SkillsCheck {
10
11
  static {
@@ -133,7 +134,7 @@ var NO_IMPLICIT = /^\s*allow_implicit_invocation:\s*false\b/m;
133
134
  var CLAUDE_PLUGIN_ROOT = "${CLAUDE_PLUGIN_ROOT}";
134
135
  var ROOT_COMMAND = "epic guide --root";
135
136
  var FRONT_MATTER = /^---\n([\s\S]*?)\n---\n([\s\S]*)$/;
136
- var SKILLS_FOLDER = join(dirname(dirname(import.meta.dirname)), "skills");
137
+ var SKILLS_FOLDER = EngineFiles.path("skills");
137
138
  export {
138
139
  CLAUDE_ONLY_TOOLS,
139
140
  DESCRIPTION_LIMIT,
@@ -128,7 +128,9 @@ var Stock = class _Stock {
128
128
  morning: morningNote(worktree, name),
129
129
  sessions: here
130
130
  };
131
- return this.classifyCheckout(item);
131
+ const classified = this.classifyCheckout(item);
132
+ if (config.baseBranchProtected) classified.actions = classified.actions?.filter(({ id }) => id !== "merge");
133
+ return classified;
132
134
  }
133
135
  /** Set `group`, `why` and `actions` on a worktree / branch item. */
134
136
  classifyCheckout(item) {
@@ -44,7 +44,7 @@ export declare class TurnEnd {
44
44
  * - its output appended to `<epic repo>/.git/spell-shared.log`; a failed commit never shows as a failed hook,
45
45
  * and the next turn's picks up anything left
46
46
  * - only in a repo set up for epics whose epic repo exists (`contentRepoOf()`): the hooks run in every repo
47
- * - `epic`: this plugin's own `bin/epic`, with its packages installed
47
+ * - `epic`: this copy's `epic` command, with its packages installed (`EngineFiles.bin`)
48
48
  * - returns the command it started, else `undefined`
49
49
  * - NEVER throws
50
50
  */
@@ -4,7 +4,8 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
4
4
  // src/command/TurnEnd.ts
5
5
  import { spawn } from "node:child_process";
6
6
  import { existsSync, openSync } from "node:fs";
7
- import { dirname, join } from "node:path";
7
+ import { join } from "node:path";
8
+ import { EngineFiles } from "../config/EngineFiles.mjs";
8
9
  import { EpicConfig } from "../config/EpicConfig.js";
9
10
  import { EXIT, EpicCommandError, parseVerbArgs, stringFlag } from "./command.types.js";
10
11
  var TurnEnd = class _TurnEnd {
@@ -62,7 +63,7 @@ var TurnEnd = class _TurnEnd {
62
63
  * - its output appended to `<epic repo>/.git/spell-shared.log`; a failed commit never shows as a failed hook,
63
64
  * and the next turn's picks up anything left
64
65
  * - only in a repo set up for epics whose epic repo exists (`contentRepoOf()`): the hooks run in every repo
65
- * - `epic`: this plugin's own `bin/epic`, with its packages installed
66
+ * - `epic`: this copy's `epic` command, with its packages installed (`EngineFiles.bin`)
66
67
  * - returns the command it started, else `undefined`
67
68
  * - NEVER throws
68
69
  */
@@ -79,7 +80,7 @@ var TurnEnd = class _TurnEnd {
79
80
  }
80
81
  }
81
82
  };
82
- var EPIC = join(dirname(dirname(import.meta.dirname)), "bin", "epic");
83
+ var EPIC = EngineFiles.bin;
83
84
  export {
84
85
  TurnEnd
85
86
  };
@@ -24,7 +24,8 @@ import { Sessions } from "./Sessions";
24
24
  * - for a person or a tool: the skills enter a worktree by its NAME, never this path (Claude Code asks before
25
25
  * entering a path outside `.claude/worktrees/`; epic `epic-engine` P16)
26
26
  * - `remove <name | path> [--force] [--branches]`: remove a worktree, its servers stopped FIRST (`remove()`, epic
27
- * `epic-engine` I53); `--branches`: and its branch in each repo, when merged (`git branch -d`)
27
+ * `epic-engine` I53); `--branches`: and its branch in each repo, when merged (`git branch -d`; a merged pull
28
+ * request counts, where the base branch takes only those)
28
29
  * - `repos [<name>] [--json]`: each repo's checkout in epic `<name>`'s worktree (default: the one this runs in),
29
30
  * with its branch, what's uncommitted, and how far it is ahead of and behind its base branch (`repoStates()`)
30
31
  * - `merge-main [--continue] [--json]`: merge `main` into this checkout's branch (`MainMerge`)
@@ -89,7 +90,8 @@ export declare class Worktrees {
89
90
  * 1. its servers stopped (`CheckoutServers.stop()`)
90
91
  * 2. `git worktree remove [--force]`: git refuses a worktree with changes, unless `force`
91
92
  * 3. its saved-session link taken away, if it's one to main's (`SessionFolders.unlink()`), as the worktree hook does
92
- * - NOT its branch: the caller deletes it (`git branch -d`), as it would after `git worktree remove`
93
+ * - NOT its branch, unless `branches`: the caller deletes it (`git branch -d`), as it would after
94
+ * `git worktree remove`
93
95
  * - refuses (`EpicCommandError`) the main checkout, a folder that isn't one of the repo's worktrees, and git's refusal
94
96
  * - what `/isolate done` (`/epic done`) and `/worktrees`' clean-up (`Stock`) run; the `WorktreeRemove` hook stops
95
97
  * the servers itself
@@ -118,8 +120,21 @@ export declare class Worktrees {
118
120
  force?: boolean | undefined;
119
121
  sessions?: string | undefined;
120
122
  }): string[];
121
- /** `git branch -d <branch>` in `main`: a line saying what happened; an unmerged branch stays, never `-D`. */
123
+ /**
124
+ * Delete `branch` in `main`, when merged: a line saying what happened; unmerged work always stays.
125
+ * - `git branch -d`, never a blind `-D`
126
+ * - a base branch that takes only pull requests: `mergedThroughPullRequest()` decides, then `-D`
127
+ * - why: `-d` refuses a squash-merged branch, and passes one that's merely pushed (it checks the upstream)
128
+ */
122
129
  static deleteBranch(main: string, branch: string): string;
130
+ /**
131
+ * Why `branch` counts as merged into `base`, in a repo whose base takes only pull requests; `undefined` if it doesn't:
132
+ * - all its commits in `base`, local or `origin`'s
133
+ * - or a pull request GitHub reports merged whose last commit holds the branch's tip:
134
+ * so a commit made since the merge keeps the branch
135
+ * - runs `gh` only when git alone can't say; `gh` missing or offline: `undefined`, and the branch stays
136
+ */
137
+ static mergedThroughPullRequest(main: string, branch: string, base: string): string | undefined;
123
138
  /** `move --idle`: move every worktree in the old place that no session works in; a report each. */
124
139
  moveIdle({ dryRun }?: {
125
140
  dryRun?: boolean;