@lorepack/cli 0.0.0-stage → 0.1.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/dist/.tsbuildinfo +1 -0
  2. package/dist/commands/activate.d.ts +20 -0
  3. package/dist/commands/activate.d.ts.map +1 -0
  4. package/dist/commands/activate.js +171 -0
  5. package/dist/commands/activate.js.map +1 -0
  6. package/dist/commands/build.d.ts +3 -0
  7. package/dist/commands/build.d.ts.map +1 -0
  8. package/dist/commands/build.js +53 -0
  9. package/dist/commands/build.js.map +1 -0
  10. package/dist/commands/config.d.ts +14 -0
  11. package/dist/commands/config.d.ts.map +1 -0
  12. package/dist/commands/config.js +109 -0
  13. package/dist/commands/config.js.map +1 -0
  14. package/dist/commands/connect.d.ts +5 -0
  15. package/dist/commands/connect.d.ts.map +1 -0
  16. package/dist/commands/connect.js +196 -0
  17. package/dist/commands/connect.js.map +1 -0
  18. package/dist/commands/deploy.d.ts +14 -0
  19. package/dist/commands/deploy.d.ts.map +1 -0
  20. package/dist/commands/deploy.js +248 -0
  21. package/dist/commands/deploy.js.map +1 -0
  22. package/dist/commands/dev.d.ts +25 -0
  23. package/dist/commands/dev.d.ts.map +1 -0
  24. package/dist/commands/dev.js +227 -0
  25. package/dist/commands/dev.js.map +1 -0
  26. package/dist/commands/diff.d.ts +3 -0
  27. package/dist/commands/diff.d.ts.map +1 -0
  28. package/dist/commands/diff.js +75 -0
  29. package/dist/commands/diff.js.map +1 -0
  30. package/dist/commands/doctor.d.ts +14 -0
  31. package/dist/commands/doctor.d.ts.map +1 -0
  32. package/dist/commands/doctor.js +96 -0
  33. package/dist/commands/doctor.js.map +1 -0
  34. package/dist/commands/export.d.ts +3 -0
  35. package/dist/commands/export.d.ts.map +1 -0
  36. package/dist/commands/export.js +126 -0
  37. package/dist/commands/export.js.map +1 -0
  38. package/dist/commands/index.d.ts +8 -0
  39. package/dist/commands/index.d.ts.map +1 -0
  40. package/dist/commands/index.js +51 -0
  41. package/dist/commands/index.js.map +1 -0
  42. package/dist/commands/init.d.ts +3 -0
  43. package/dist/commands/init.d.ts.map +1 -0
  44. package/dist/commands/init.js +95 -0
  45. package/dist/commands/init.js.map +1 -0
  46. package/dist/commands/inspect.d.ts +15 -0
  47. package/dist/commands/inspect.d.ts.map +1 -0
  48. package/dist/commands/inspect.js +527 -0
  49. package/dist/commands/inspect.js.map +1 -0
  50. package/dist/commands/mcp.d.ts +12 -0
  51. package/dist/commands/mcp.d.ts.map +1 -0
  52. package/dist/commands/mcp.js +219 -0
  53. package/dist/commands/mcp.js.map +1 -0
  54. package/dist/commands/pack.d.ts +9 -0
  55. package/dist/commands/pack.d.ts.map +1 -0
  56. package/dist/commands/pack.js +57 -0
  57. package/dist/commands/pack.js.map +1 -0
  58. package/dist/commands/plan.d.ts +3 -0
  59. package/dist/commands/plan.d.ts.map +1 -0
  60. package/dist/commands/plan.js +44 -0
  61. package/dist/commands/plan.js.map +1 -0
  62. package/dist/commands/prune.d.ts +7 -0
  63. package/dist/commands/prune.d.ts.map +1 -0
  64. package/dist/commands/prune.js +341 -0
  65. package/dist/commands/prune.js.map +1 -0
  66. package/dist/commands/search.d.ts +3 -0
  67. package/dist/commands/search.d.ts.map +1 -0
  68. package/dist/commands/search.js +84 -0
  69. package/dist/commands/search.js.map +1 -0
  70. package/dist/commands/serve.d.ts +20 -0
  71. package/dist/commands/serve.d.ts.map +1 -0
  72. package/dist/commands/serve.js +66 -0
  73. package/dist/commands/serve.js.map +1 -0
  74. package/dist/commands/status.d.ts +3 -0
  75. package/dist/commands/status.d.ts.map +1 -0
  76. package/dist/commands/status.js +27 -0
  77. package/dist/commands/status.js.map +1 -0
  78. package/dist/commands/target.d.ts +71 -0
  79. package/dist/commands/target.d.ts.map +1 -0
  80. package/dist/commands/target.js +945 -0
  81. package/dist/commands/target.js.map +1 -0
  82. package/dist/entry.d.ts +3 -0
  83. package/dist/entry.d.ts.map +1 -0
  84. package/dist/entry.js +19 -0
  85. package/dist/entry.js.map +1 -0
  86. package/dist/framework/context.d.ts +49 -0
  87. package/dist/framework/context.d.ts.map +1 -0
  88. package/dist/framework/context.js +47 -0
  89. package/dist/framework/context.js.map +1 -0
  90. package/dist/framework/exit.d.ts +36 -0
  91. package/dist/framework/exit.d.ts.map +1 -0
  92. package/dist/framework/exit.js +57 -0
  93. package/dist/framework/exit.js.map +1 -0
  94. package/dist/framework/metadata.d.ts +38 -0
  95. package/dist/framework/metadata.d.ts.map +1 -0
  96. package/dist/framework/metadata.js +47 -0
  97. package/dist/framework/metadata.js.map +1 -0
  98. package/dist/framework/program.d.ts +47 -0
  99. package/dist/framework/program.d.ts.map +1 -0
  100. package/dist/framework/program.js +189 -0
  101. package/dist/framework/program.js.map +1 -0
  102. package/dist/index.d.ts +7 -0
  103. package/dist/index.d.ts.map +1 -0
  104. package/dist/index.js +7 -0
  105. package/dist/index.js.map +1 -0
  106. package/dist/migrations/README.md +7 -0
  107. package/dist/migrations/build/0001_catalog.sql +85 -0
  108. package/dist/migrations/build/0002_tables.sql +43 -0
  109. package/dist/migrations/build/0003_table-cell-range.sql +13 -0
  110. package/dist/migrations/build/0004_chunk-page.sql +11 -0
  111. package/dist/migrations/state/0001_state.sql +40 -0
  112. package/dist/public-entry.js +38563 -0
  113. package/dist/public-entry.js.map +7 -0
  114. package/dist/public-index.js +36428 -0
  115. package/dist/public-index.js.map +7 -0
  116. package/dist/services/build.d.ts +48 -0
  117. package/dist/services/build.d.ts.map +1 -0
  118. package/dist/services/build.js +499 -0
  119. package/dist/services/build.js.map +1 -0
  120. package/dist/services/builds.d.ts +40 -0
  121. package/dist/services/builds.d.ts.map +1 -0
  122. package/dist/services/builds.js +184 -0
  123. package/dist/services/builds.js.map +1 -0
  124. package/dist/services/cancellation.d.ts +27 -0
  125. package/dist/services/cancellation.d.ts.map +1 -0
  126. package/dist/services/cancellation.js +41 -0
  127. package/dist/services/cancellation.js.map +1 -0
  128. package/dist/services/cloudflare-target.d.ts +38 -0
  129. package/dist/services/cloudflare-target.d.ts.map +1 -0
  130. package/dist/services/cloudflare-target.js +471 -0
  131. package/dist/services/cloudflare-target.js.map +1 -0
  132. package/dist/services/comparer.d.ts +15 -0
  133. package/dist/services/comparer.d.ts.map +1 -0
  134. package/dist/services/comparer.js +43 -0
  135. package/dist/services/comparer.js.map +1 -0
  136. package/dist/services/config-resolve.d.ts +60 -0
  137. package/dist/services/config-resolve.d.ts.map +1 -0
  138. package/dist/services/config-resolve.js +178 -0
  139. package/dist/services/config-resolve.js.map +1 -0
  140. package/dist/services/deploy.d.ts +70 -0
  141. package/dist/services/deploy.d.ts.map +1 -0
  142. package/dist/services/deploy.js +260 -0
  143. package/dist/services/deploy.js.map +1 -0
  144. package/dist/services/dev-session.d.ts +52 -0
  145. package/dist/services/dev-session.d.ts.map +1 -0
  146. package/dist/services/dev-session.js +102 -0
  147. package/dist/services/dev-session.js.map +1 -0
  148. package/dist/services/doctor.d.ts +35 -0
  149. package/dist/services/doctor.d.ts.map +1 -0
  150. package/dist/services/doctor.js +389 -0
  151. package/dist/services/doctor.js.map +1 -0
  152. package/dist/services/export.d.ts +20 -0
  153. package/dist/services/export.d.ts.map +1 -0
  154. package/dist/services/export.js +129 -0
  155. package/dist/services/export.js.map +1 -0
  156. package/dist/services/init.d.ts +46 -0
  157. package/dist/services/init.d.ts.map +1 -0
  158. package/dist/services/init.js +231 -0
  159. package/dist/services/init.js.map +1 -0
  160. package/dist/services/packing.d.ts +25 -0
  161. package/dist/services/packing.d.ts.map +1 -0
  162. package/dist/services/packing.js +69 -0
  163. package/dist/services/packing.js.map +1 -0
  164. package/dist/services/parse-cache.d.ts +47 -0
  165. package/dist/services/parse-cache.d.ts.map +1 -0
  166. package/dist/services/parse-cache.js +65 -0
  167. package/dist/services/parse-cache.js.map +1 -0
  168. package/dist/services/project.d.ts +49 -0
  169. package/dist/services/project.d.ts.map +1 -0
  170. package/dist/services/project.js +119 -0
  171. package/dist/services/project.js.map +1 -0
  172. package/dist/services/remote-prune.d.ts +7 -0
  173. package/dist/services/remote-prune.d.ts.map +1 -0
  174. package/dist/services/remote-prune.js +34 -0
  175. package/dist/services/remote-prune.js.map +1 -0
  176. package/dist/services/retention.d.ts +20 -0
  177. package/dist/services/retention.d.ts.map +1 -0
  178. package/dist/services/retention.js +106 -0
  179. package/dist/services/retention.js.map +1 -0
  180. package/dist/services/revalidate.d.ts +36 -0
  181. package/dist/services/revalidate.d.ts.map +1 -0
  182. package/dist/services/revalidate.js +73 -0
  183. package/dist/services/revalidate.js.map +1 -0
  184. package/dist/services/search.d.ts +25 -0
  185. package/dist/services/search.d.ts.map +1 -0
  186. package/dist/services/search.js +88 -0
  187. package/dist/services/search.js.map +1 -0
  188. package/dist/services/serving.d.ts +70 -0
  189. package/dist/services/serving.d.ts.map +1 -0
  190. package/dist/services/serving.js +240 -0
  191. package/dist/services/serving.js.map +1 -0
  192. package/dist/services/status.d.ts +54 -0
  193. package/dist/services/status.d.ts.map +1 -0
  194. package/dist/services/status.js +203 -0
  195. package/dist/services/status.js.map +1 -0
  196. package/dist/services/studio-assets.d.ts +13 -0
  197. package/dist/services/studio-assets.d.ts.map +1 -0
  198. package/dist/services/studio-assets.js +94 -0
  199. package/dist/services/studio-assets.js.map +1 -0
  200. package/dist/services/studio-diagnostics.d.ts +28 -0
  201. package/dist/services/studio-diagnostics.d.ts.map +1 -0
  202. package/dist/services/studio-diagnostics.js +88 -0
  203. package/dist/services/studio-diagnostics.js.map +1 -0
  204. package/dist/services/studio-endpoints.d.ts +61 -0
  205. package/dist/services/studio-endpoints.d.ts.map +1 -0
  206. package/dist/services/studio-endpoints.js +88 -0
  207. package/dist/services/studio-endpoints.js.map +1 -0
  208. package/dist/services/studio-mutations.d.ts +32 -0
  209. package/dist/services/studio-mutations.d.ts.map +1 -0
  210. package/dist/services/studio-mutations.js +149 -0
  211. package/dist/services/studio-mutations.js.map +1 -0
  212. package/dist/services/versions.d.ts +38 -0
  213. package/dist/services/versions.d.ts.map +1 -0
  214. package/dist/services/versions.js +46 -0
  215. package/dist/services/versions.js.map +1 -0
  216. package/dist/services/watch.d.ts +103 -0
  217. package/dist/services/watch.d.ts.map +1 -0
  218. package/dist/services/watch.js +420 -0
  219. package/dist/services/watch.js.map +1 -0
  220. package/package.json +73 -4
  221. package/studio-dist/assets/ibm-plex-mono-latin-400-normal-Dm_PoFIZ.woff2 +0 -0
  222. package/studio-dist/assets/ibm-plex-mono-latin-500-normal-C_OblDzq.woff2 +0 -0
  223. package/studio-dist/assets/ibm-plex-sans-latin-400-normal-CDDApCn2.woff2 +0 -0
  224. package/studio-dist/assets/ibm-plex-sans-latin-500-normal-6ng42L7E.woff2 +0 -0
  225. package/studio-dist/assets/ibm-plex-sans-latin-600-normal-CuJfVYMP.woff2 +0 -0
  226. package/studio-dist/assets/index-BuAYbQVX.js +66 -0
  227. package/studio-dist/assets/index-C_3XEUt4.css +1 -0
  228. package/studio-dist/index.html +30 -0
  229. package/README.md +0 -3
@@ -0,0 +1,341 @@
1
+ import { join } from 'node:path';
2
+ import { ProjectLock } from '@lorepack/backend-local';
3
+ import { count, LORE_DIRECTORY, LoreError, loadConfig, } from '@lorepack/core';
4
+ import { applyRemoteRetentionPlan, planRemoteRetention, } from '@lorepack/deploy-cloudflare';
5
+ import { openStateStore } from '../services/builds.js';
6
+ import { createWranglerDeployAdapter, resolveCloudflareResourcesWithAdapter, } from '../services/cloudflare-target.js';
7
+ import { readRemotePruneReceipt, remotePruneReceiptId, remotePruneReceiptPath, writeRemotePruneReceipt, } from '../services/remote-prune.js';
8
+ import { applyRetention, DEFAULT_KEEP_PREVIOUS, planRetention, renderRetentionPlan, } from '../services/retention.js';
9
+ export function pruneCommand(options = {}) {
10
+ return {
11
+ name: 'prune',
12
+ description: 'Remove old builds, keeping the active one and the previous five.',
13
+ flags: [
14
+ {
15
+ flags: '--keep <count>',
16
+ description: `previous builds to keep (default ${DEFAULT_KEEP_PREVIOUS})`,
17
+ },
18
+ { flags: '--target <target>', description: 'plan cleanup for a remote deployment target' },
19
+ { flags: '--resume <receipt-id>', description: 'continue an interrupted remote cleanup' },
20
+ { flags: '--yes', description: 'apply the plan instead of only printing it' },
21
+ ],
22
+ handler: async (_args, flags, context) => {
23
+ const targetName = typeof flags.target === 'string' && flags.target.trim() !== '' ? flags.target.trim() : null;
24
+ const resumeId = typeof flags.resume === 'string' && flags.resume.trim() !== '' ? flags.resume.trim() : null;
25
+ if (resumeId !== null && targetName === null) {
26
+ throw new LoreError('LORE_E_INVALID_ARGUMENT', 'Remote cleanup resume requires `--target cloudflare`.', {
27
+ remediation: 'Run `lorepack prune --target cloudflare --yes --resume <receipt-id>`.',
28
+ subject: resumeId,
29
+ });
30
+ }
31
+ if (targetName !== null) {
32
+ return await pruneRemote(targetName, flags.yes === true, flags.keep, context.options.cwd, options.cloudflareAdapter, resumeId);
33
+ }
34
+ const config = loadConfig({ cwd: context.options.cwd });
35
+ const loreDirectory = join(config.projectRoot, LORE_DIRECTORY);
36
+ const state = openStateStore(loreDirectory);
37
+ try {
38
+ const keep = parseKeep(flags.keep);
39
+ const plan = planRetention(loreDirectory, state.listBuilds(), state.current()?.buildId ?? null, keep);
40
+ // Deletion is never the default. A plan that prints and stops is recoverable; one
41
+ // that deletes because it was run is not.
42
+ if (flags.yes !== true) {
43
+ // Only offer `--yes` when it would do something. Telling a user to re-run a
44
+ // command that has nothing to remove is an instruction to no purpose.
45
+ const next = plan.remove.length === 0 ? '' : '\n\nNothing was removed. Re-run with --yes to apply.';
46
+ return {
47
+ human: `${renderRetentionPlan(plan)}${next}`,
48
+ json: { ...plan, applied: false },
49
+ };
50
+ }
51
+ const lock = new ProjectLock(join(loreDirectory, 'lock'));
52
+ await lock.withLock(() => {
53
+ for (const id of plan.remove)
54
+ state.forgetBuild(id);
55
+ applyRetention(loreDirectory, plan);
56
+ });
57
+ // "Removed." after "Nothing to remove." claimed a deletion that never happened.
58
+ const outcome = plan.remove.length === 0
59
+ ? ''
60
+ : `\n\nRemoved ${count(plan.remove.length, 'build')} and ${count(plan.objectsToRemove.length, 'object')}.`;
61
+ return {
62
+ human: `${renderRetentionPlan(plan)}${outcome}`,
63
+ json: { ...plan, applied: true },
64
+ };
65
+ }
66
+ finally {
67
+ state.close();
68
+ }
69
+ },
70
+ };
71
+ }
72
+ function parseKeep(raw) {
73
+ if (raw === undefined)
74
+ return DEFAULT_KEEP_PREVIOUS;
75
+ const value = Number(raw);
76
+ if (!Number.isInteger(value) || value < 0) {
77
+ throw new LoreError('LORE_E_INVALID_ARGUMENT', `--keep must be a whole number, got ${raw}.`, {
78
+ remediation: 'Pass a count, for example `--keep 10`.',
79
+ });
80
+ }
81
+ return value;
82
+ }
83
+ async function pruneRemote(targetName, apply, keepRaw, cwd, cloudflareAdapter, resumeId) {
84
+ if (targetName !== 'cloudflare') {
85
+ throw new LoreError('LORE_E_INVALID_ARGUMENT', `Unknown prune target ${targetName}.`, {
86
+ remediation: 'Use `cloudflare`. Additional remote prune targets are not implemented in v0.1.',
87
+ subject: targetName,
88
+ });
89
+ }
90
+ if (resumeId !== null && !apply) {
91
+ throw new LoreError('LORE_E_INVALID_ARGUMENT', 'Remote cleanup resume requires `--yes`.', {
92
+ remediation: 'Run `lorepack prune --target cloudflare --yes --resume <receipt-id>`.',
93
+ subject: resumeId,
94
+ });
95
+ }
96
+ const config = loadConfig({ cwd });
97
+ if (resumeId !== null) {
98
+ return await resumeRemotePrune(config.projectRoot, keepRaw, resumeId, cloudflareAdapter ?? createWranglerDeployAdapter());
99
+ }
100
+ const resolved = await resolveCloudflareResourcesWithAdapter(config.projectRoot, cloudflareAdapter ?? createWranglerDeployAdapter());
101
+ const keep = parseKeep(keepRaw);
102
+ if (!apply) {
103
+ const plan = await planRemoteRetention(resolved.catalogDb, resolved.receipt.project, keep);
104
+ return {
105
+ human: renderRemoteRetentionPlan(plan),
106
+ json: {
107
+ target: 'cloudflare',
108
+ applied: false,
109
+ ...plan,
110
+ },
111
+ };
112
+ }
113
+ const plan = await planRemoteRetention(resolved.catalogDb, resolved.receipt.project, keep);
114
+ if (plan.remove.length === 0) {
115
+ return {
116
+ human: `Nothing to remove remotely. ${count(plan.keep.length, 'build')} retained.`,
117
+ json: {
118
+ target: 'cloudflare',
119
+ applied: true,
120
+ ...zeroRemovalResult(plan),
121
+ },
122
+ };
123
+ }
124
+ const receipt = createRemotePruneReceipt(resolved.receipt.project, keep, plan);
125
+ return await applyRemotePruneWithReceipt(config.projectRoot, receipt, resolved.catalogDb, resolved.objects);
126
+ }
127
+ function renderRemoteRetentionPlan(plan) {
128
+ if (plan.remove.length === 0) {
129
+ return `Nothing to remove remotely. ${count(plan.keep.length, 'build')} retained.`;
130
+ }
131
+ const lines = [
132
+ `Cloudflare cleanup plan: removing ${count(plan.remove.length, 'remote build')}, keeping ${plan.keep.length}:`,
133
+ '',
134
+ ];
135
+ for (const buildId of plan.remove)
136
+ lines.push(` - ${buildId}`);
137
+ lines.push('');
138
+ lines.push(` ${count(plan.archiveKeysToRemove.length, 'build archive')}`);
139
+ lines.push(` ${count(plan.objectKeysToRemove.length, 'unreferenced object')}`);
140
+ lines.push('');
141
+ lines.push('Nothing was removed. Re-run with --yes to apply.');
142
+ return lines.join('\n');
143
+ }
144
+ function renderRemoteRetentionApplyResult(result) {
145
+ if (result.remove.length === 0) {
146
+ return `Nothing to remove remotely. ${count(result.keep.length, 'build')} retained.`;
147
+ }
148
+ const lines = [
149
+ `Cloudflare cleanup applied: removed ${count(result.remove.length, 'remote build')}, kept ${result.keep.length}.`,
150
+ '',
151
+ `D1 rows removed: ${renderD1Counts(result)}`,
152
+ `R2 objects removed: ${count(result.r2.archiveKeysRemoved.length, 'build archive')} and ${count(result.r2.objectKeysRemoved.length, 'unreferenced object')}.`,
153
+ ];
154
+ if (result.d1.physicalTablesDropped.length > 0) {
155
+ lines.push(`Dropped ${count(result.d1.physicalTablesDropped.length, 'physical table')}.`);
156
+ }
157
+ return lines.join('\n');
158
+ }
159
+ async function resumeRemotePrune(projectRoot, keepRaw, resumeId, cloudflareAdapter) {
160
+ const receipt = readRemotePruneReceipt(projectRoot, resumeId);
161
+ if (keepRaw !== undefined) {
162
+ const keep = parseKeep(keepRaw);
163
+ if (keep !== receipt.keepPrevious) {
164
+ throw new LoreError('LORE_E_INVALID_ARGUMENT', `Receipt ${resumeId} was created with --keep ${receipt.keepPrevious}, not ${keep}.`, {
165
+ remediation: 'Resume with the original keep count, or start a fresh cleanup from the beginning.',
166
+ subject: resumeId,
167
+ });
168
+ }
169
+ }
170
+ if (receipt.state === 'applied') {
171
+ return {
172
+ human: renderRemoteRetentionApplyResult(resultFromReceipt(receipt)),
173
+ json: {
174
+ target: 'cloudflare',
175
+ receiptId: receipt.receiptId,
176
+ applied: true,
177
+ ...resultFromReceipt(receipt),
178
+ },
179
+ };
180
+ }
181
+ const resolved = await resolveCloudflareResourcesWithAdapter(projectRoot, cloudflareAdapter);
182
+ if (resolved.receipt.project !== receipt.project) {
183
+ throw new LoreError('LORE_E_TARGET_NOT_CONFIGURED', `Receipt ${resumeId} belongs to project ${receipt.project}, but the current Cloudflare target receipt points at ${resolved.receipt.project}.`, {
184
+ remediation: 'Restore the matching Cloudflare target receipt or restart cleanup against the current target.',
185
+ subject: resumeId,
186
+ });
187
+ }
188
+ return await applyRemotePruneWithReceipt(projectRoot, receipt, resolved.catalogDb, resolved.objects);
189
+ }
190
+ async function applyRemotePruneWithReceipt(projectRoot, receipt, catalogDb, objects) {
191
+ const applyingReceipt = {
192
+ ...receipt,
193
+ state: 'applying',
194
+ };
195
+ writeRemotePruneReceipt(projectRoot, applyingReceipt);
196
+ try {
197
+ const result = await applyRemoteRetentionPlan(catalogDb, objects, receipt.plan, resumeStateFromReceipt(receipt));
198
+ const finished = {
199
+ ...receipt,
200
+ state: 'applied',
201
+ completedSteps: ['plan', 'd1', 'archives', 'objects'],
202
+ d1: cloneD1Report(result.d1),
203
+ r2: cloneR2Report(result.r2),
204
+ };
205
+ writeRemotePruneReceipt(projectRoot, finished);
206
+ return {
207
+ human: `${renderRemoteRetentionApplyResult(result)}\nReceipt: ${remotePruneReceiptPath(projectRoot, finished.receiptId)}`,
208
+ json: {
209
+ target: 'cloudflare',
210
+ receiptId: finished.receiptId,
211
+ applied: true,
212
+ ...result,
213
+ },
214
+ };
215
+ }
216
+ catch (error) {
217
+ const failed = receiptForFailure(receipt, error);
218
+ writeRemotePruneReceipt(projectRoot, failed);
219
+ throw new LoreError('LORE_E_REMOTE_DEPLOY', `Cloudflare cleanup failed while removing ${count(receipt.plan.remove.length, 'remote build')}.`, {
220
+ remediation: `Completed cleanup work was recorded. Resume with \`lorepack prune --target cloudflare --yes --resume ${receipt.receiptId}\`.`,
221
+ details: { receiptId: receipt.receiptId },
222
+ cause: error,
223
+ });
224
+ }
225
+ }
226
+ function renderD1Counts(result) {
227
+ return [
228
+ `${count(result.d1.projectedBuildsRemoved, 'projected build')}`,
229
+ `${count(result.d1.buildManifestsRemoved, 'manifest')}`,
230
+ `${count(result.d1.buildWarningsRemoved, 'warning')}`,
231
+ `${count(result.d1.artifactsRemoved, 'artifact')}`,
232
+ `${count(result.d1.supersessionsRemoved, 'supersession')}`,
233
+ `${count(result.d1.nodesRemoved, 'node')}`,
234
+ `${count(result.d1.chunksRemoved, 'chunk')}`,
235
+ `${count(result.d1.ftsRowsRemoved, 'fts row')}`,
236
+ `${count(result.d1.projectedTablesRemoved, 'projected table')}`,
237
+ `${count(result.d1.projectedTableColumnsRemoved, 'projected table column')}`,
238
+ ].join(', ');
239
+ }
240
+ function createRemotePruneReceipt(project, keepPrevious, plan) {
241
+ return {
242
+ formatVersion: 1,
243
+ receiptId: remotePruneReceiptId(plan.activeBuildId ?? plan.keep[0] ?? plan.remove[0] ?? null),
244
+ target: 'cloudflare',
245
+ project,
246
+ keepPrevious,
247
+ createdAt: new Date().toISOString(),
248
+ state: 'planned',
249
+ completedSteps: ['plan'],
250
+ plan: clonePlanForReceipt(plan),
251
+ d1: cloneD1Report(zeroRemovalResult(plan).d1),
252
+ r2: cloneR2Report(zeroRemovalResult(plan).r2),
253
+ };
254
+ }
255
+ function zeroRemovalResult(plan) {
256
+ return {
257
+ ...plan,
258
+ d1: {
259
+ projectedBuildsRemoved: 0,
260
+ buildManifestsRemoved: 0,
261
+ buildWarningsRemoved: 0,
262
+ artifactsRemoved: 0,
263
+ supersessionsRemoved: 0,
264
+ nodesRemoved: 0,
265
+ chunksRemoved: 0,
266
+ ftsRowsRemoved: 0,
267
+ projectedTablesRemoved: 0,
268
+ projectedTableColumnsRemoved: 0,
269
+ physicalTablesDropped: [],
270
+ },
271
+ r2: {
272
+ archiveKeysRemoved: [],
273
+ objectKeysRemoved: [],
274
+ },
275
+ };
276
+ }
277
+ function resumeStateFromReceipt(receipt) {
278
+ return {
279
+ d1Completed: receipt.completedSteps.includes('d1'),
280
+ archivesCompleted: receipt.completedSteps.includes('archives'),
281
+ objectsCompleted: receipt.completedSteps.includes('objects'),
282
+ d1: receipt.d1,
283
+ archiveKeysRemoved: receipt.r2.archiveKeysRemoved,
284
+ objectKeysRemoved: receipt.r2.objectKeysRemoved,
285
+ };
286
+ }
287
+ function resultFromReceipt(receipt) {
288
+ return {
289
+ activeBuildId: receipt.plan.activeBuildId,
290
+ keep: [...receipt.plan.keep],
291
+ remove: [...receipt.plan.remove],
292
+ archiveKeysToRemove: [...receipt.plan.archiveKeysToRemove],
293
+ objectKeysToRemove: [...receipt.plan.objectKeysToRemove],
294
+ d1: cloneD1Report(receipt.d1),
295
+ r2: cloneR2Report(receipt.r2),
296
+ };
297
+ }
298
+ function receiptForFailure(receipt, error) {
299
+ return {
300
+ ...receipt,
301
+ state: 'failed',
302
+ completedSteps: completedStepsFromResumeState(error.progress),
303
+ d1: cloneD1Report(error.progress.d1),
304
+ r2: cloneR2Report({
305
+ archiveKeysRemoved: error.progress.archiveKeysRemoved,
306
+ objectKeysRemoved: error.progress.objectKeysRemoved,
307
+ }),
308
+ };
309
+ }
310
+ function completedStepsFromResumeState(state) {
311
+ const completed = ['plan'];
312
+ if (state.d1Completed)
313
+ completed.push('d1');
314
+ if (state.archivesCompleted)
315
+ completed.push('archives');
316
+ if (state.objectsCompleted)
317
+ completed.push('objects');
318
+ return completed;
319
+ }
320
+ function clonePlanForReceipt(plan) {
321
+ return {
322
+ activeBuildId: plan.activeBuildId,
323
+ keep: [...plan.keep],
324
+ remove: [...plan.remove],
325
+ archiveKeysToRemove: [...plan.archiveKeysToRemove],
326
+ objectKeysToRemove: [...plan.objectKeysToRemove],
327
+ };
328
+ }
329
+ function cloneD1Report(report) {
330
+ return {
331
+ ...report,
332
+ physicalTablesDropped: [...report.physicalTablesDropped],
333
+ };
334
+ }
335
+ function cloneR2Report(report) {
336
+ return {
337
+ archiveKeysRemoved: [...report.archiveKeysRemoved],
338
+ objectKeysRemoved: [...report.objectKeysRemoved],
339
+ };
340
+ }
341
+ //# sourceMappingURL=prune.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prune.js","sourceRoot":"","sources":["../../src/commands/prune.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EACL,KAAK,EACL,cAAc,EACd,SAAS,EACT,UAAU,GAEX,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,wBAAwB,EACxB,mBAAmB,GAKpB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAEL,2BAA2B,EAC3B,qCAAqC,GACtC,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,aAAa,EACb,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AAMlC,MAAM,UAAU,YAAY,CAAC,OAAO,GAAwB,EAAE;IAC5D,OAA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AAC,IAAyB;IACpD,OAAO;QACL,aAAa,EAAE,IAAI,CAAC,aAAa;QACjC,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC;QACpB,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;QACxB,mBAAmB,EAAE,CAAC,GAAG,IAAI,CAAC,mBAAmB,CAAC;QAClD,kBAAkB,EAAE,CAAC,GAAG,IAAI,CAAC,kBAAkB,CAAC;KACjD,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,MAAwC;IAC7D,OAAO;QACL,GAAG,MAAM;QACT,qBAAqB,EAAE,CAAC,GAAG,MAAM,CAAC,qBAAqB,CAAC;KACzD,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,MAAwC;IAC7D,OAAO;QACL,kBAAkB,EAAE,CAAC,GAAG,MAAM,CAAC,kBAAkB,CAAC;QAClD,iBAAiB,EAAE,CAAC,GAAG,MAAM,CAAC,iBAAiB,CAAC;KACjD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { CommandDefinition } from '../framework/program.js';
2
+ export declare function searchCommand(): CommandDefinition;
3
+ //# sourceMappingURL=search.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/commands/search.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,yBAAyB,CAAC;AAIhF,wBAAgB,aAAa,IAAI,iBAAiB,CAuDjD"}
@@ -0,0 +1,84 @@
1
+ import { LoreError, loadConfig } from '@lorepack/core';
2
+ import { renderSearch, runSearch } from '../services/search.js';
3
+ import { readFreshness } from '../services/status.js';
4
+ export function searchCommand() {
5
+ return {
6
+ name: 'search',
7
+ description: 'Search the active build. Every result carries its source location.',
8
+ arguments: [{ name: 'query', description: 'what to look for' }],
9
+ flags: [
10
+ { flags: '--limit <count>', description: 'results to return (default 10)' },
11
+ { flags: '--path <glob>', description: 'restrict to paths matching a glob' },
12
+ { flags: '--type <extension>', description: 'restrict to one file extension' },
13
+ {
14
+ flags: '--source <artifact>',
15
+ description: 'restrict to one document, by path or artifact id',
16
+ },
17
+ {
18
+ flags: '--include-archived',
19
+ description: 'include archived and superseded sources, which are labelled',
20
+ },
21
+ { flags: '--debug', description: 'show why each result ranked where it did' },
22
+ ],
23
+ handler: async (args, flags, context) => {
24
+ const config = loadConfig({ cwd: context.options.cwd });
25
+ const query = args[0] ?? '';
26
+ // Freshness travels with the answer (section 4.10): a result from a stale build is
27
+ // still a result, but the reader has to be told which build it came from. It is an
28
+ // annotation, never a precondition, so failing to establish it degrades the label
29
+ // rather than the query. See `readFreshness`.
30
+ const freshness = await readFreshness({ config });
31
+ const result = await runSearch({
32
+ config,
33
+ query,
34
+ sourceState: freshness.sourceState,
35
+ limit: parseLimit(flags.limit),
36
+ includeArchived: flags.includeArchived === true,
37
+ debug: flags.debug === true,
38
+ ...(typeof flags.path === 'string' ? { pathGlob: filter('--path', flags.path) } : {}),
39
+ ...(typeof flags.type === 'string' ? { type: filter('--type', flags.type) } : {}),
40
+ ...(typeof flags.source === 'string'
41
+ ? { artifactId: filter('--source', flags.source) }
42
+ : {}),
43
+ });
44
+ // On stderr, so `--json` stdout stays the structured result alone. A consumer reading
45
+ // JSON sees `sourceState: "unknown"`, which is what the contract's third state means.
46
+ if (freshness.reason !== null) {
47
+ context.warn(`Freshness unknown: ${freshness.reason}\n`);
48
+ }
49
+ return {
50
+ human: renderSearch(result, query, context.options.verbose || flags.debug === true),
51
+ json: result,
52
+ };
53
+ },
54
+ };
55
+ }
56
+ /**
57
+ * A filter has to filter something.
58
+ *
59
+ * An empty value is what an unset shell variable expands to, and passing it through returns
60
+ * "no matches" for a query that would otherwise have answered. That is a wrong answer
61
+ * wearing the clothes of a right one, which is worse than an error. The protocol surfaces
62
+ * already refuse it (`artifactId` is `min(1)`), so refusing here also makes the CLI and the
63
+ * API agree.
64
+ */
65
+ function filter(flag, value) {
66
+ if (value.trim() !== '')
67
+ return value;
68
+ throw new LoreError('LORE_E_INVALID_ARGUMENT', `${flag} was given an empty value.`, {
69
+ remediation: `Pass something for ${flag}, or leave the flag off to search everything.`,
70
+ subject: flag,
71
+ });
72
+ }
73
+ function parseLimit(raw) {
74
+ if (raw === undefined)
75
+ return 10;
76
+ const value = Number(raw);
77
+ if (!Number.isInteger(value) || value < 1 || value > 100) {
78
+ throw new LoreError('LORE_E_INVALID_ARGUMENT', `--limit must be between 1 and 100, got ${raw}.`, {
79
+ remediation: 'Pass a whole number, for example `--limit 20`.',
80
+ });
81
+ }
82
+ return value;
83
+ }
84
+ //# sourceMappingURL=search.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search.js","sourceRoot":"","sources":["../../src/commands/search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,MAAM,UAAU,aAAa;IAC3B,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,oEAAoE;QACjF,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,CAAC;QAC/D,KAAK,EAAE;YACL,EAAE,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,gCAAgC,EAAE;YAC3E,EAAE,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,mCAAmC,EAAE;YAC5E,EAAE,KAAK,EAAE,oBAAoB,EAAE,WAAW,EAAE,gCAAgC,EAAE;YAC9E;gBACE,KAAK,EAAE,qBAAqB;gBAC5B,WAAW,EAAE,kDAAkD;aAChE;YACD;gBACE,KAAK,EAAE,oBAAoB;gBAC3B,WAAW,EAAE,6DAA6D;aAC3E;YACD,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,E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ACtF,sFAAsF;YACtF,IAAI,SAAS,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;gBAC9B,OAAO,CAAC,IAAI,CAAC,sBAAsB,SAAS,CAAC,MAAM,IAAI,CAAC,CAAC;YAC3D,CAAC;YAED,OAAO;gBACL,KAAK,EAAE,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,OAAO,IAAI,KAAK,CAAC,KAAK,KAAK,IAAI,CAAC;gBACnF,IAAI,EAAE,MAAM;aACb,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,MAAM,CAAC,IAAY,EAAE,KAAa;IACzC,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE;QAAE,OAAO,KAAK,CAAC;IACtC,MAAM,IAAI,SAAS,CAAC,yBAAyB,EAAE,GAAG,IAAI,4BAA4B,EAAE;QAClF,WAAW,EAAE,sBAAsB,IAAI,+CAA+C;QACtF,OAAO,EAAE,IAAI;KACd,CAAC,CAAC;AACL,CAAC;AAED,SAAS,UAAU,CAAC,GAAY;IAC9B,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IACjC,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAC1B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,GAAG,EAAE,CAAC;QACzD,MAAM,IAAI,SAAS,CACjB,yBAAyB,EACzB,0CAA0C,GAAG,GAAG,EAChD;YACE,WAAW,EAAE,gDAAgD;SAC9D,CACF,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { CommandDefinition } from '../framework/program.js';
2
+ import { SERVE_DEFAULTS } from '../services/serving.js';
3
+ /**
4
+ * `lorepack serve`: the read-only server for whatever build is active.
5
+ *
6
+ * It does not watch, fingerprint on a timer, or build. That is `lorepack dev`'s job, and keeping
7
+ * them apart is what makes this one safe to leave running: a server that rebuilds on its own
8
+ * is a server that can change what a client sees mid-conversation for reasons the client
9
+ * cannot see.
10
+ *
11
+ * What it does do is re-read the active pointer on every request, so `lorepack build` or
12
+ * `lorepack rollback` in another terminal is picked up at the next request with no restart
13
+ * (architecture 15.2).
14
+ *
15
+ * The serving itself lives in `services/serving.ts`, because `lorepack dev` serves the same way
16
+ * and a second implementation would be a second port policy and a second way to drain.
17
+ */
18
+ export declare function serveCommand(): CommandDefinition;
19
+ export { SERVE_DEFAULTS };
20
+ //# sourceMappingURL=serve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../src/commands/serve.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,yBAAyB,CAAC;AAEhF,OAAO,EAGL,cAAc,EAGf,MAAM,wBAAwB,CAAC;AAEhC;;;;;;;;;;;;;;GAcG;AAEH,wBAAgB,YAAY,IAAI,iBAAiB,CAmDhD;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -0,0 +1,66 @@
1
+ import { loadConfig } from '@lorepack/core';
2
+ import { DEFAULT_REVALIDATE_INTERVAL_MS } from '../services/revalidate.js';
3
+ import { parseInterval, parsePort, SERVE_DEFAULTS, startServing, untilInterrupted, } from '../services/serving.js';
4
+ /**
5
+ * `lorepack serve`: the read-only server for whatever build is active.
6
+ *
7
+ * It does not watch, fingerprint on a timer, or build. That is `lorepack dev`'s job, and keeping
8
+ * them apart is what makes this one safe to leave running: a server that rebuilds on its own
9
+ * is a server that can change what a client sees mid-conversation for reasons the client
10
+ * cannot see.
11
+ *
12
+ * What it does do is re-read the active pointer on every request, so `lorepack build` or
13
+ * `lorepack rollback` in another terminal is picked up at the next request with no restart
14
+ * (architecture 15.2).
15
+ *
16
+ * The serving itself lives in `services/serving.ts`, because `lorepack dev` serves the same way
17
+ * and a second implementation would be a second port policy and a second way to drain.
18
+ */
19
+ export function serveCommand() {
20
+ return {
21
+ name: 'serve',
22
+ description: 'Serve the active build over HTTP and MCP. Read-only, and never rebuilds.',
23
+ flags: [
24
+ {
25
+ flags: '--port <number>',
26
+ description: `port to listen on (default ${SERVE_DEFAULTS.port})`,
27
+ },
28
+ { flags: '--host <address>', description: 'address to bind (default 127.0.0.1)' },
29
+ {
30
+ flags: '--revalidate-interval <ms>',
31
+ description: 'how often to recheck the sources (default 5000, 0 every request)',
32
+ },
33
+ ],
34
+ handler: async (_args, flags, context) => {
35
+ const config = loadConfig({ cwd: context.options.cwd });
36
+ const host = typeof flags.host === 'string' ? flags.host : '127.0.0.1';
37
+ const server = await startServing({
38
+ config,
39
+ host,
40
+ port: parsePort(flags.port),
41
+ warn: context.warn,
42
+ // Rechecked on an interval with a cheap metadata prescreen inside it, so a server
43
+ // left running all day stays honest without hashing the corpus per request (#112).
44
+ revalidateIntervalMs: flags.revalidateInterval === undefined
45
+ ? DEFAULT_REVALIDATE_INTERVAL_MS
46
+ : parseInterval(flags.revalidateInterval),
47
+ });
48
+ context.write([
49
+ `Serving ${config.config.name} from build ${server.buildId.slice(0, 17)}`,
50
+ '',
51
+ ` REST ${server.url}/v1`,
52
+ ` MCP ${server.url}/mcp`,
53
+ ` Health ${server.url}/health`,
54
+ '',
55
+ 'Read-only. `lorepack build` in another terminal is picked up on the next request.',
56
+ 'Press Ctrl-C to stop.',
57
+ '',
58
+ ].join('\n'));
59
+ await untilInterrupted(context.warn);
60
+ await server.close();
61
+ return { human: '', json: undefined };
62
+ },
63
+ };
64
+ }
65
+ export { SERVE_DEFAULTS };
66
+ //# sourceMappingURL=serve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serve.js","sourceRoot":"","sources":["../../src/commands/serve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAE,8BAA8B,EAAE,MAAM,2BAA2B,CAAC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AE,EAAE,CAAC,EAAE;gBACzE,EAAE;gBACF,WAAW,MAAM,CAAC,GAAG,KAAK;gBAC1B,WAAW,MAAM,CAAC,GAAG,MAAM;gBAC3B,YAAY,MAAM,CAAC,GAAG,SAAS;gBAC/B,EAAE;gBACF,mFAAmF;gBACnF,uBAAuB;gBACvB,EAAE;aACH,CAAC,IAAI,CAAC,IAAI,CAAC,CACb,CAAC;YAEF,MAAM,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACrC,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;YACrB,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QACxC,CAAC;KACF,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { CommandDefinition } from '../framework/program.js';
2
+ export declare function statusCommand(): CommandDefinition;
3
+ //# sourceMappingURL=status.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../src/commands/status.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,yBAAyB,CAAC;AAGhF,wBAAgB,aAAa,IAAI,iBAAiB,CAwBjD"}
@@ -0,0 +1,27 @@
1
+ import { loadConfig } from '@lorepack/core';
2
+ import { readStatus, renderStatus } from '../services/status.js';
3
+ export function statusCommand() {
4
+ return {
5
+ name: 'status',
6
+ description: 'Report whether the active build still matches the sources.',
7
+ flags: [
8
+ { flags: '--exit-code', description: 'exit 2 when sources are dirty, for scripting' },
9
+ { flags: '--allow-large-project', description: 'continue past the supported file count' },
10
+ ],
11
+ handler: async (_args, flags, context) => {
12
+ const config = loadConfig({ cwd: context.options.cwd });
13
+ const status = await readStatus({
14
+ config,
15
+ progress: context.progress,
16
+ allowLargeProject: flags.allowLargeProject === true,
17
+ });
18
+ return {
19
+ human: renderStatus(status, context.options.verbose),
20
+ json: status,
21
+ // Dirty is a normal state, not a failure, so the non-zero exit is opt-in.
22
+ ...(flags.exitCode === true && status.sourceState === 'dirty' ? { exitCode: 2 } : {}),
23
+ };
24
+ },
25
+ };
26
+ }
27
+ //# sourceMappingURL=status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.js","sourceRoot":"","sources":["../../src/commands/status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAEjE,MAAM,UAAU,aAAa;IAC3B,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,4DAA4D;QACzE,KAAK,EAAE;YACL,EAAE,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,8CAA8C,EAAE;YACrF,EAAE,KAAK,EAAE,uBAAuB,EAAE,WAAW,EAAE,wCAAwC,EAAE;SAC1F;QACD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAA0B,EAAE;YAC/D,MAAM,MAAM,GAAG,UAAU,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;YACxD,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC;gBAC9B,MAAM;gBACN,QAAQ,EAAE,OAAO,CAAC,QAAQ;gBAC1B,iBAAiB,EAAE,KAAK,CAAC,iBAAiB,KAAK,IAAI;aACpD,CAAC,CAAC;YAEH,OAAO;gBACL,KAAK,EAAE,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC;gBACpD,IAAI,EAAE,MAAM;gBACZ,0EAA0E;gBAC1E,GAAG,CAAC,KAAK,CAAC,QAAQ,KAAK,IAAI,IAAI,MAAM,CAAC,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACtF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}