@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,96 @@
1
+ import { count, loadConfig } from '@lorepack/core';
2
+ import { DEV_PORT, isRunning, readReceipt } from '../services/dev-session.js';
3
+ import { runDoctor } from '../services/doctor.js';
4
+ /**
5
+ * `lorepack doctor`: when something is wrong, one command names it and says what to do.
6
+ *
7
+ * Architecture 6.5 and 6.9. Everything here is read-only, so it is safe to run at any time,
8
+ * including against a project that is mid-build, and it works in a directory that is not a
9
+ * project at all: reporting the environment is useful before there is anything to configure.
10
+ *
11
+ * The checks themselves live in `services/doctor.ts` because Phase 4's Studio Diagnostics
12
+ * route (#69) renders the same results over HTTP, and two implementations of "what is wrong
13
+ * with this environment" would be two answers to one question.
14
+ */
15
+ export function doctorCommand() {
16
+ return {
17
+ name: 'doctor',
18
+ description: 'Check this environment and project, and say how to fix what is wrong.',
19
+ flags: [
20
+ {
21
+ flags: '--ci',
22
+ description: 'exit non-zero when any check fails, for use in a pipeline',
23
+ },
24
+ { flags: '--port <number>', description: 'the dev port to test (default 43110)' },
25
+ ],
26
+ handler: async (_args, flags, context) => {
27
+ const port = flags.port === undefined ? undefined : Number(flags.port);
28
+ const report = await runDoctor({
29
+ cwd: context.options.cwd,
30
+ ...(port === undefined ? {} : { port }),
31
+ // A dev session of this project holding the port is not a problem to report, and
32
+ // running doctor while your own `lorepack dev` is up is the common case. Studio reaches
33
+ // the same conclusion from the other side, so the two never disagree.
34
+ portHeldByThisProject: heldByThisProject(context.options.cwd, port),
35
+ });
36
+ return {
37
+ human: render(report),
38
+ json: report,
39
+ // Without `--ci` a failed check is information, not a failed command: someone
40
+ // running doctor to read it has not done anything wrong. With it, the exit code is
41
+ // the whole point (architecture 18.8).
42
+ ...(flags.ci === true && report.status === 'fail' ? { exitCode: 1 } : {}),
43
+ };
44
+ },
45
+ };
46
+ }
47
+ /**
48
+ * Whether the port under test is held by this project's own live dev session.
49
+ *
50
+ * Read from the receipt, which is evidence rather than a lock, so the pid is checked: a
51
+ * receipt left behind by a crash names a process that is gone, and believing it would report
52
+ * a genuinely occupied port as fine.
53
+ */
54
+ function heldByThisProject(cwd, port) {
55
+ try {
56
+ const config = loadConfig({ cwd });
57
+ const receipt = readReceipt(config);
58
+ if (receipt === null || !isRunning(receipt.pid))
59
+ return false;
60
+ return receipt.port === (port ?? DEV_PORT);
61
+ }
62
+ catch {
63
+ // No project, or one that will not load. Either way there is no session to credit, and
64
+ // doctor's whole job is to keep working in exactly those directories.
65
+ return false;
66
+ }
67
+ }
68
+ const MARK = { pass: 'ok', warn: 'warn', fail: 'FAIL' };
69
+ function render(report) {
70
+ const lines = [];
71
+ lines.push(report.project === null
72
+ ? 'No project here. Checking the environment only.'
73
+ : `Project ${report.project}`);
74
+ lines.push('');
75
+ for (const check of report.checks) {
76
+ lines.push(` ${MARK[check.status].padEnd(5)} ${check.title.padEnd(22)} ${check.detail}`);
77
+ if (check.remediation !== undefined) {
78
+ // Indented under the check it belongs to, and never truncated: the remediation is the
79
+ // reason the command exists.
80
+ for (const line of check.remediation.split('\n'))
81
+ lines.push(` ${line}`);
82
+ }
83
+ }
84
+ lines.push('');
85
+ if (report.counts.fail > 0) {
86
+ lines.push(`${count(report.counts.fail, 'check')} failed. Fix the ones marked FAIL above.`);
87
+ }
88
+ else if (report.counts.warn > 0) {
89
+ lines.push(`Everything essential works. ${count(report.counts.warn, 'check')} worth knowing about.`);
90
+ }
91
+ else {
92
+ lines.push('Everything checks out.');
93
+ }
94
+ return lines.join('\n');
95
+ }
96
+ //# sourceMappingURL=doctor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"doctor.js","sourceRoot":"","sources":["../../src/commands/doctor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEnD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9E,OAAO,EAAuC,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvF;;;;;;;;;;GAUG;AAEH,MAAM,UAAU,aAAa;IAC3B,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,uEAAuE;QACpF,KAAK,EAAE;YACL;gBACE,KAAK,EAAE,MAAM;gBACb,WAAW,EAAE,2DAA2D;aACzE;YACD,EAAE,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,sCAAsC,EAAE;SAClF;QACD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAA0B,EAAE;YAC/D,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACvE,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC;gBAC7B,GAAG,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG;gBACxB,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,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@
1
+ import type { CommandDefinition } from '../framework/program.js';
2
+ export declare function exportCommand(): CommandDefinition;
3
+ //# sourceMappingURL=export.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../../src/commands/export.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,yBAAyB,CAAC;AAkBhF,wBAAgB,aAAa,IAAI,iBAAiB,CAmFjD"}
@@ -0,0 +1,126 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { isAbsolute, resolve } from 'node:path';
3
+ import { createLocalRuntimeBackend } from '@lorepack/backend-local';
4
+ import { contextProfileSchema, LoreError, loadConfig, writeFileAtomic, } from '@lorepack/core';
5
+ import { createRuntime } from '@lorepack/runtime';
6
+ import { renderBundleMarkdown } from '../services/export.js';
7
+ import { readFreshness } from '../services/status.js';
8
+ /**
9
+ * `lorepack export`: one file a person can paste into any chat product.
10
+ *
11
+ * Architecture 14.6 calls this the universal compatibility bridge, and that is the honest
12
+ * framing: MCP is better, and most chat products cannot speak it. The output is bounded,
13
+ * cited, and explicit about what did not fit, because a context bundle that quietly
14
+ * dropped half the corpus is indistinguishable from one that had nothing else to give.
15
+ *
16
+ * Defaults to the `chat` profile and its 24,000 token budget, which is the profile sized
17
+ * for exactly this: one paste, one bounded file.
18
+ */
19
+ const EXPORT_PROFILE = 'chat';
20
+ export function exportCommand() {
21
+ return {
22
+ name: 'export',
23
+ description: 'Write a bounded, cited context bundle for a task. Markdown or JSON.',
24
+ flags: [
25
+ { flags: '--task <text>', description: 'what the context is for' },
26
+ { flags: '--profile <name>', description: 'agent, coding, chat or deep (default chat)' },
27
+ { flags: '--budget <tokens>', description: 'estimated token budget, overriding the profile' },
28
+ { flags: '--format <format>', description: 'markdown or json (default markdown)' },
29
+ { flags: '--output <file>', description: 'write to a file instead of stdout' },
30
+ { flags: '--force', description: 'overwrite an existing output file' },
31
+ {
32
+ flags: '--allow-unsupported-budget',
33
+ description: 'permit a budget outside the supported 4,000 to 40,000 range',
34
+ },
35
+ ],
36
+ handler: async (_args, flags, context) => {
37
+ const config = loadConfig({ cwd: context.options.cwd });
38
+ const task = typeof flags.task === 'string' ? flags.task.trim() : '';
39
+ if (task === '') {
40
+ throw new LoreError('LORE_E_INVALID_ARGUMENT', 'An export needs a task to select for.', {
41
+ remediation: 'Pass --task "what you are trying to do".',
42
+ });
43
+ }
44
+ const format = parseFormat(flags.format);
45
+ const profile = parseProfile(flags.profile);
46
+ const output = typeof flags.output === 'string' ? absolute(flags.output, config) : null;
47
+ if (output !== null && existsSync(output) && flags.force !== true) {
48
+ throw new LoreError('LORE_E_INVALID_ARGUMENT', `${flags.output} already exists.`, {
49
+ remediation: 'Pass --force to overwrite it, or choose another --output path.',
50
+ subject: String(flags.output),
51
+ });
52
+ }
53
+ const freshness = await readFreshness({ config });
54
+ const backend = createLocalRuntimeBackend({
55
+ projectRoot: config.projectRoot,
56
+ freshness: async () => freshness.sourceState,
57
+ });
58
+ try {
59
+ if ((await backend.provider.current()) === null) {
60
+ throw new LoreError('LORE_E_BUILD_NOT_FOUND', 'This project has no build to export.', {
61
+ remediation: 'Run `lorepack build` first.',
62
+ });
63
+ }
64
+ const bundle = await createRuntime(backend).contextForTask({
65
+ task,
66
+ profile,
67
+ includeArchived: false,
68
+ allowUnsupportedBudget: flags.allowUnsupportedBudget === true,
69
+ ...(flags.budget === undefined ? {} : { budget: parseBudget(flags.budget) }),
70
+ });
71
+ const rendered = format === 'json'
72
+ ? `${JSON.stringify(bundle, null, 2)}\n`
73
+ : renderBundleMarkdown(bundle, {
74
+ projectName: config.config.name,
75
+ sourceState: bundle.sourceState,
76
+ moreCommand: `lorepack export --task ${JSON.stringify(task)} --profile deep`,
77
+ });
78
+ if (output === null) {
79
+ // stdout carries the export and nothing else, so `lorepack export ... > file.md` and
80
+ // `--output file.md` produce the same bytes.
81
+ return { human: rendered.trimEnd(), json: bundle };
82
+ }
83
+ // Atomic, because a half-written context file that looks complete is worse than no
84
+ // file: a person would paste it without noticing.
85
+ writeFileAtomic(output, rendered);
86
+ context.warn(`Wrote ${output}\n ${bundle.estimatedTokens} estimated tokens of ${bundle.budget}, ${bundle.citations.length} citations, ${bundle.omitted.length} omitted.\n`);
87
+ return { human: '', json: { ...bundle, output } };
88
+ }
89
+ finally {
90
+ backend.close();
91
+ }
92
+ },
93
+ };
94
+ }
95
+ function parseFormat(raw) {
96
+ if (raw === undefined)
97
+ return 'markdown';
98
+ if (raw === 'markdown' || raw === 'json')
99
+ return raw;
100
+ throw new LoreError('LORE_E_INVALID_ARGUMENT', `--format must be markdown or json, got ${raw}.`, {
101
+ remediation: 'Pass --format markdown for a file to paste, or --format json for a program.',
102
+ });
103
+ }
104
+ function parseProfile(raw) {
105
+ if (raw === undefined)
106
+ return EXPORT_PROFILE;
107
+ const parsed = contextProfileSchema.safeParse(raw);
108
+ if (parsed.success)
109
+ return parsed.data;
110
+ throw new LoreError('LORE_E_INVALID_ARGUMENT', `--profile must be one of agent, coding, chat, deep, got ${raw}.`, {
111
+ remediation: 'Omit it for `chat`, which is sized for one paste into a chat product.',
112
+ });
113
+ }
114
+ function parseBudget(raw) {
115
+ const value = Number(raw);
116
+ if (!Number.isInteger(value) || value < 1) {
117
+ throw new LoreError('LORE_E_INVALID_ARGUMENT', `--budget must be a whole number, got ${raw}.`, {
118
+ remediation: 'Pass an estimated token budget, for example --budget 24000.',
119
+ });
120
+ }
121
+ return value;
122
+ }
123
+ function absolute(path, config) {
124
+ return isAbsolute(path) ? path : resolve(config.projectRoot, path);
125
+ }
126
+ //# sourceMappingURL=export.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export.js","sourceRoot":"","sources":["../../src/commands/export.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAy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AAC,CAAC;AACrE,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { CommandDefinition } from '../framework/program.js';
2
+ /**
3
+ * Commands are registered explicitly. No dynamic discovery: architecture section 4.8
4
+ * applies to the CLI as much as to adapters, and an explicit list is what makes
5
+ * `lorepack --help` reviewable in a pull request.
6
+ */
7
+ export declare function registerCommands(): CommandDefinition[];
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAqBjE;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,iBAAiB,EAAE,CAyBtD"}
@@ -0,0 +1,51 @@
1
+ import { activateCommand, buildsCommand, rollbackCommand } from './activate.js';
2
+ import { buildCommand } from './build.js';
3
+ import { configCommand } from './config.js';
4
+ import { connectCommand, disconnectCommand } from './connect.js';
5
+ import { deployCommand } from './deploy.js';
6
+ import { devCommand } from './dev.js';
7
+ import { diffCommand } from './diff.js';
8
+ import { doctorCommand } from './doctor.js';
9
+ import { exportCommand } from './export.js';
10
+ import { initCommand } from './init.js';
11
+ import { inspectCommand } from './inspect.js';
12
+ import { mcpCommand } from './mcp.js';
13
+ import { packCommand } from './pack.js';
14
+ import { planCommand } from './plan.js';
15
+ import { pruneCommand } from './prune.js';
16
+ import { searchCommand } from './search.js';
17
+ import { serveCommand } from './serve.js';
18
+ import { statusCommand } from './status.js';
19
+ import { targetCommand } from './target.js';
20
+ /**
21
+ * Commands are registered explicitly. No dynamic discovery: architecture section 4.8
22
+ * applies to the CLI as much as to adapters, and an explicit list is what makes
23
+ * `lorepack --help` reviewable in a pull request.
24
+ */
25
+ export function registerCommands() {
26
+ return [
27
+ initCommand(),
28
+ planCommand(),
29
+ buildCommand(),
30
+ statusCommand(),
31
+ diffCommand(),
32
+ searchCommand(),
33
+ inspectCommand(),
34
+ packCommand(),
35
+ buildsCommand(),
36
+ activateCommand(),
37
+ rollbackCommand(),
38
+ pruneCommand(),
39
+ devCommand(),
40
+ deployCommand(),
41
+ targetCommand(),
42
+ connectCommand(),
43
+ disconnectCommand(),
44
+ doctorCommand(),
45
+ configCommand(),
46
+ mcpCommand(),
47
+ serveCommand(),
48
+ exportCommand(),
49
+ ];
50
+ }
51
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C;;;;GAIG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO;QACL,WAAW,EAAE;QACb,WAAW,EAAE;QACb,YAAY,EAAE;QACd,aAAa,EAAE;QACf,WAAW,EAAE;QACb,aAAa,EAAE;QACf,cAAc,EAAE;QAChB,WAAW,EAAE;QACb,aAAa,EAAE;QACf,eAAe,EAAE;QACjB,eAAe,EAAE;QACjB,YAAY,EAAE;QACd,UAAU,EAAE;QACZ,aAAa,EAAE;QACf,aAAa,EAAE;QACf,cAAc,EAAE;QAChB,iBAAiB,EAAE;QACnB,aAAa,EAAE;QACf,aAAa,EAAE;QACf,UAAU,EAAE;QACZ,YAAY,EAAE;QACd,aAAa,EAAE;KAChB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { CommandDefinition } from '../framework/program.js';
2
+ export declare function initCommand(): CommandDefinition;
3
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,yBAAyB,CAAC;AAkEhF,wBAAgB,WAAW,IAAI,iBAAiB,CAiC/C"}
@@ -0,0 +1,95 @@
1
+ import { isAbsolute, resolve } from 'node:path';
2
+ import { CONFIG_FILENAME, count, LoreError } from '@lorepack/core';
3
+ import { enclosingProject, planInit, runInit } from '../services/init.js';
4
+ /**
5
+ * The verb the run earned, rather than the one the flag implies.
6
+ *
7
+ * `--force` rewrites files and used to announce "Created:" over a list marked `~`, and a
8
+ * run with nothing to do said "Created:" over the word "nothing" (#178). The markers were
9
+ * right both times; only the heading was making things up.
10
+ */
11
+ function heading(result, dryRun) {
12
+ const created = result.creates.length > 0;
13
+ const rewritten = result.modifies.length > 0;
14
+ if (!created && !rewritten)
15
+ return dryRun ? 'Nothing to create.' : 'Nothing to do.';
16
+ if (created && rewritten)
17
+ return dryRun ? 'Would create and rewrite:' : 'Created and rewrote:';
18
+ if (created)
19
+ return dryRun ? 'Would create:' : 'Created:';
20
+ return dryRun ? 'Would rewrite:' : 'Rewrote:';
21
+ }
22
+ function renderHuman(result, dryRun) {
23
+ const lines = [];
24
+ if (result.alreadyInitialized && result.written.length === 0 && !dryRun) {
25
+ lines.push(`Already initialized: ${CONFIG_FILENAME} exists. Nothing was changed.`);
26
+ if (result.creates.length > 0) {
27
+ lines.push('');
28
+ lines.push('Created the missing files:');
29
+ for (const file of result.creates)
30
+ lines.push(` + ${file}`);
31
+ }
32
+ if (result.forceWouldChange.length > 0) {
33
+ lines.push('');
34
+ lines.push(result.configDiffers
35
+ ? 'Your configuration differs from a freshly generated one. `--force` would overwrite:'
36
+ : '`--force` would rewrite:');
37
+ for (const file of result.forceWouldChange)
38
+ lines.push(` ~ ${file}`);
39
+ }
40
+ }
41
+ else {
42
+ lines.push(heading(result, dryRun));
43
+ for (const file of result.creates)
44
+ lines.push(` + ${file}`);
45
+ for (const file of result.modifies)
46
+ lines.push(` ~ ${file}`);
47
+ }
48
+ if (result.secretShaped.length > 0) {
49
+ lines.push('');
50
+ lines.push(`Warning: ${count(result.secretShaped.length, 'file')} ${result.secretShaped.length === 1 ? 'looks' : 'look'} like credentials and will never be indexed:`);
51
+ for (const file of result.secretShaped.slice(0, 10))
52
+ lines.push(` ${file}`);
53
+ if (result.secretShaped.length > 10) {
54
+ lines.push(` and ${result.secretShaped.length - 10} more`);
55
+ }
56
+ lines.push('This is a guardrail on filenames, not a secret scanner.');
57
+ }
58
+ if (!dryRun && result.written.length > 0) {
59
+ lines.push('');
60
+ lines.push('Next: run `lorepack build` to create your first build.');
61
+ }
62
+ return lines.join('\n');
63
+ }
64
+ export function initCommand() {
65
+ return {
66
+ name: 'init',
67
+ description: 'Create a minimal Lorepack project in a directory.',
68
+ arguments: [{ name: 'path', description: 'project directory (default: .)', required: false }],
69
+ flags: [
70
+ { flags: '--force', description: 'overwrite existing Lorepack configuration' },
71
+ { flags: '--dry-run', description: 'show what would change without writing' },
72
+ ],
73
+ handler: (args, flags, context) => {
74
+ const directory = resolveDirectory(args[0], context);
75
+ const force = flags.force === true;
76
+ const dryRun = flags.dryRun === true;
77
+ const enclosing = enclosingProject(directory);
78
+ if (enclosing !== null && !force) {
79
+ throw new LoreError('LORE_E_INVALID_ARGUMENT', `${directory} is already inside a Lorepack project rooted at ${enclosing}.`, {
80
+ remediation: 'Nested projects are not supported. Run `lorepack build` in the existing project, or pass --force if you really want a separate one.',
81
+ });
82
+ }
83
+ const result = dryRun
84
+ ? { ...planInit({ directory, force, dryRun: true }), written: [] }
85
+ : runInit({ directory, force });
86
+ return { human: renderHuman(result, dryRun), json: result };
87
+ },
88
+ };
89
+ }
90
+ function resolveDirectory(argument, context) {
91
+ if (argument === undefined)
92
+ return context.options.cwd;
93
+ return isAbsolute(argument) ? resolve(argument) : resolve(context.options.cwd, argument);
94
+ }
95
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGnE,OAAO,EAAE,gBAAgB,EAAmB,QAAQ,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE3F;;;;;;GAMG;AACH,SAAS,OAAO,CAAC,MAAkB,EAAE,MAAe;IAClD,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;IAC1C,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IAE7C,IAAI,CAAC,OAAO,IAAI,CAAC,SAAS;QAAE,OAAO,MAAM,CAAC,CAAC,CAA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AE,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC9D,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB,CAAC,QAA4B,EAAE,OAAuB;IAC7E,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC;IACvD,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;AAC3F,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { CommandDefinition } from '../framework/program.js';
2
+ export declare function inspectCommand(): CommandDefinition;
3
+ /**
4
+ * The ordinal path a node id ends with, as numbers.
5
+ *
6
+ * `demo:docs/a.md#0.1.2` is `[0, 1, 2]`. Numbers rather than the string, because a
7
+ * lexicographic sort puts the tenth sibling before the second.
8
+ */
9
+ export declare function ordinalPath(id: string): number[];
10
+ /** A row from the `nodes` table, as `node:sqlite` hands it back. */
11
+ type NodeRow = Record<string, string | number | null>;
12
+ /** Document order: every node after its parent, siblings in the order they were written. */
13
+ export declare function orderByTree(nodes: readonly NodeRow[]): NodeRow[];
14
+ export {};
15
+ //# sourceMappingURL=inspect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inspect.d.ts","sourceRoot":"","sources":["../../src/commands/inspect.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,yBAAyB,CAAC;AA2BhF,wBAAgB,cAAc,IAAI,iBAAiB,CA6DlD;AA8PD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAOhD;AAED,oEAAoE;AACpE,KAAK,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC,CAAC;AAEtD,4FAA4F;AAC5F,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,OAAO,EAAE,GAAG,OAAO,EAAE,CAUhE"}