mossbear 0.1.0-alpha.113 → 0.1.0-alpha.115

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 (128) hide show
  1. package/dist/action-queue.d.ts.map +1 -1
  2. package/dist/action-queue.js +22 -1
  3. package/dist/action-queue.js.map +1 -1
  4. package/dist/agent-comment-client.d.ts +1 -37
  5. package/dist/agent-comment-client.d.ts.map +1 -1
  6. package/dist/agent-comment-client.js +0 -50
  7. package/dist/agent-comment-client.js.map +1 -1
  8. package/dist/artifacts/artifact-comments-client.d.ts +3 -77
  9. package/dist/artifacts/artifact-comments-client.d.ts.map +1 -1
  10. package/dist/artifacts/artifact-comments-client.js +3 -103
  11. package/dist/artifacts/artifact-comments-client.js.map +1 -1
  12. package/dist/artifacts/classify.d.ts +1 -1
  13. package/dist/artifacts/classify.js +1 -1
  14. package/dist/artifacts/delivered-skill-twins.d.ts.map +1 -1
  15. package/dist/artifacts/delivered-skill-twins.js +1 -0
  16. package/dist/artifacts/delivered-skill-twins.js.map +1 -1
  17. package/dist/artifacts/global-delivery.d.ts.map +1 -1
  18. package/dist/artifacts/global-delivery.js +4 -1
  19. package/dist/artifacts/global-delivery.js.map +1 -1
  20. package/dist/artifacts/global-namespace.d.ts.map +1 -1
  21. package/dist/artifacts/global-namespace.js +6 -4
  22. package/dist/artifacts/global-namespace.js.map +1 -1
  23. package/dist/artifacts/publication.d.ts +75 -0
  24. package/dist/artifacts/publication.d.ts.map +1 -0
  25. package/dist/artifacts/publication.js +163 -0
  26. package/dist/artifacts/publication.js.map +1 -0
  27. package/dist/artifacts/sidecar.d.ts +4 -32
  28. package/dist/artifacts/sidecar.d.ts.map +1 -1
  29. package/dist/artifacts/sidecar.js +15 -174
  30. package/dist/artifacts/sidecar.js.map +1 -1
  31. package/dist/artifacts/sync-acquisition.d.ts +51 -0
  32. package/dist/artifacts/sync-acquisition.d.ts.map +1 -0
  33. package/dist/artifacts/sync-acquisition.js +84 -0
  34. package/dist/artifacts/sync-acquisition.js.map +1 -0
  35. package/dist/artifacts/sync-artifacts.d.ts +49 -91
  36. package/dist/artifacts/sync-artifacts.d.ts.map +1 -1
  37. package/dist/artifacts/sync-artifacts.js +10 -773
  38. package/dist/artifacts/sync-artifacts.js.map +1 -1
  39. package/dist/artifacts/sync-execution.d.ts +1 -1
  40. package/dist/artifacts/sync-execution.d.ts.map +1 -1
  41. package/dist/artifacts/sync-execution.js +15 -0
  42. package/dist/artifacts/sync-execution.js.map +1 -1
  43. package/dist/artifacts/sync-report.d.ts +91 -1
  44. package/dist/artifacts/sync-report.d.ts.map +1 -1
  45. package/dist/artifacts/sync-report.js +661 -0
  46. package/dist/artifacts/sync-report.js.map +1 -1
  47. package/dist/commands/comment.d.ts +1 -1
  48. package/dist/commands/comment.d.ts.map +1 -1
  49. package/dist/commands/comment.js +7 -10
  50. package/dist/commands/comment.js.map +1 -1
  51. package/dist/commands/comments.d.ts.map +1 -1
  52. package/dist/commands/comments.js +1 -4
  53. package/dist/commands/comments.js.map +1 -1
  54. package/dist/commands/mcp.d.ts.map +1 -1
  55. package/dist/commands/mcp.js +2 -4
  56. package/dist/commands/mcp.js.map +1 -1
  57. package/dist/commands/publish.d.ts +3 -1
  58. package/dist/commands/publish.d.ts.map +1 -1
  59. package/dist/commands/publish.js +103 -162
  60. package/dist/commands/publish.js.map +1 -1
  61. package/dist/commands/recommend-dismissal.d.ts.map +1 -1
  62. package/dist/commands/recommend-dismissal.js +3 -2
  63. package/dist/commands/recommend-dismissal.js.map +1 -1
  64. package/dist/commands/search.d.ts +1 -1
  65. package/dist/commands/search.d.ts.map +1 -1
  66. package/dist/commands/search.js +3 -5
  67. package/dist/commands/search.js.map +1 -1
  68. package/dist/context/materialize.d.ts +2 -0
  69. package/dist/context/materialize.d.ts.map +1 -1
  70. package/dist/context/materialize.js +23 -4
  71. package/dist/context/materialize.js.map +1 -1
  72. package/dist/guides/init-import.d.ts +2 -12
  73. package/dist/guides/init-import.d.ts.map +1 -1
  74. package/dist/guides/init-import.js +2 -21
  75. package/dist/guides/init-import.js.map +1 -1
  76. package/dist/guides/payload.d.ts +1 -1
  77. package/dist/guides/payload.js +1 -1
  78. package/dist/hook-logger.d.ts +2 -0
  79. package/dist/hook-logger.d.ts.map +1 -1
  80. package/dist/hook-logger.js +32 -4
  81. package/dist/hook-logger.js.map +1 -1
  82. package/dist/http-retry.d.ts.map +1 -1
  83. package/dist/http-retry.js +30 -1
  84. package/dist/http-retry.js.map +1 -1
  85. package/dist/lifecycle/publish-from-branch.d.ts.map +1 -1
  86. package/dist/lifecycle/publish-from-branch.js +121 -178
  87. package/dist/lifecycle/publish-from-branch.js.map +1 -1
  88. package/dist/mcp/client.d.ts +113 -1
  89. package/dist/mcp/client.d.ts.map +1 -1
  90. package/dist/mcp/client.js +220 -1
  91. package/dist/mcp/client.js.map +1 -1
  92. package/dist/mcp/operations.d.ts +2 -25
  93. package/dist/mcp/operations.d.ts.map +1 -1
  94. package/dist/mcp/operations.js +24 -62
  95. package/dist/mcp/operations.js.map +1 -1
  96. package/dist/mcp/server.d.ts.map +1 -1
  97. package/dist/mcp/server.js +12 -11
  98. package/dist/mcp/server.js.map +1 -1
  99. package/dist/mossbear-paths.d.ts +0 -15
  100. package/dist/mossbear-paths.d.ts.map +1 -1
  101. package/dist/mossbear-paths.js +0 -15
  102. package/dist/mossbear-paths.js.map +1 -1
  103. package/dist/skill-identity.d.ts +8 -0
  104. package/dist/skill-identity.d.ts.map +1 -1
  105. package/dist/skill-identity.js +60 -0
  106. package/dist/skill-identity.js.map +1 -1
  107. package/dist/state/machine-cache.d.ts +2 -2
  108. package/dist/state/machine-cache.d.ts.map +1 -1
  109. package/dist/state/machine-cache.js +3 -4
  110. package/dist/state/machine-cache.js.map +1 -1
  111. package/dist/usage/snapshot-state.d.ts +2 -2
  112. package/package.json +4 -4
  113. package/dist/finding-dismissals-client.d.ts +0 -28
  114. package/dist/finding-dismissals-client.d.ts.map +0 -1
  115. package/dist/finding-dismissals-client.js +0 -25
  116. package/dist/finding-dismissals-client.js.map +0 -1
  117. package/dist/guides/guide-baseline.d.ts +0 -58
  118. package/dist/guides/guide-baseline.d.ts.map +0 -1
  119. package/dist/guides/guide-baseline.js +0 -133
  120. package/dist/guides/guide-baseline.js.map +0 -1
  121. package/dist/search-client.d.ts +0 -59
  122. package/dist/search-client.d.ts.map +0 -1
  123. package/dist/search-client.js +0 -130
  124. package/dist/search-client.js.map +0 -1
  125. package/dist/session-digest-client.d.ts +0 -36
  126. package/dist/session-digest-client.d.ts.map +0 -1
  127. package/dist/session-digest-client.js +0 -60
  128. package/dist/session-digest-client.js.map +0 -1
@@ -1,7 +1,17 @@
1
1
  /** Report settled sync effects without granting writes or re-running observations. */
2
+ import { homedir } from 'node:os';
2
3
  import { basename, join, resolve } from 'node:path';
4
+ import { MAX_CONTEXT_CONTENT_BYTES } from '@mossbear/protocol';
3
5
  import { isPathWithin } from '../guides/path-contains.js';
6
+ import { MOSSBEAR_GLOBAL_DIR } from '../mossbear-paths.js';
7
+ import { withCount } from '../plural.js';
8
+ import { displayWidth, severityPrefix, terminalWidth, wrapHanging, wrapText, } from '../terminal.js';
4
9
  import { dedupeDeliveredComments } from './artifact-comments.js';
10
+ import { MAX_BUNDLE_PULL } from './bundle-pull-limit.js';
11
+ import { formatSkillTwinLines } from './delivered-skill-twins.js';
12
+ import { displayFileName } from './display-path.js';
13
+ import { deliveryRootDir } from './global-namespace.js';
14
+ import { MOSSBEAR_CONTEXT_DIR, classifyArtifactPlacement } from './guide-projection.js';
5
15
  import { toSidecarPath } from './sidecar.js';
6
16
  import { renderArtifactResults, renderRetirement, renderStrandedForeign, renderStrandedLiteral, renderStrandedTwins, } from './sync-plan.js';
7
17
  /**
@@ -188,4 +198,655 @@ export function stateUnreadableResult(err) {
188
198
  plan: { relink: [], bundles: [], retirement: { licensed: false, decisions: [] } },
189
199
  };
190
200
  }
201
+ /**
202
+ * Report lines for everything that happened **outside** the bundle folders —
203
+ * printed by the sync command after the per-bundle lines, which cannot carry
204
+ * them: those are scoped to one folder and name files by basename.
205
+ *
206
+ * Once a doc lands at its own declared path this is no longer a guide-projection
207
+ * report, so it says "files outside the bundle folders" rather than "projected
208
+ * guide files". It covers removals, failed removals, and — since slice 2 — the
209
+ * two ways a file is *kept*: unsafe to remove, and `--no-prune`. A kept file
210
+ * that nothing names is indistinguishable from one nothing noticed.
211
+ *
212
+ * Empty when nothing out-of-dir happened.
213
+ *
214
+ * Takes only the fields it reads, not a whole `ArtifactsSyncResult`. A formatter that
215
+ * demands the entire return value forces every caller — and every test fixture —
216
+ * to fabricate parts it never looks at, which is how adding `plan` to
217
+ * `ArtifactsSyncResult` broke two test files that only ever wanted these seven lists.
218
+ */
219
+ /** How a delivery root is named to the user: by the path, never by its key. */
220
+ function deliveryRootLabel(root, homeDir = homedir()) {
221
+ return deliveryRootDir(root, homeDir);
222
+ }
223
+ /**
224
+ * What global delivery refused and what it kept, named.
225
+ *
226
+ * **Silence here is the failure mode this exists for.** A skill Mossbear
227
+ * declined to write because the directory was already someone else's, and a
228
+ * delivered file left behind because it no longer matches what we recorded, are
229
+ * both states the user can only act on if they are told — and both are invisible
230
+ * from inside the repo they are syncing.
231
+ *
232
+ * Nothing is printed for a root that was never consented to: that is not an
233
+ * event, and repeating it every sync would be nagging about a decision already
234
+ * made. `mossbear status` is where the consent state lives.
235
+ */
236
+ export function globalDeliveryLines(outcomes) {
237
+ const lines = [];
238
+ for (const outcome of outcomes) {
239
+ if (outcome.skippedForConsent)
240
+ continue;
241
+ const where = deliveryRootLabel(outcome.root);
242
+ // **Counted apart, because they are different sentences.** A guide that was
243
+ // refused did not arrive; a member that was refused arrived beside a guide
244
+ // that did. Counting them together makes the header's number wrong about the
245
+ // very thing it names — a skill delivered with one script missing would be
246
+ // reported as a guide nobody got.
247
+ const refusedSkills = outcome.refused.filter((entry) => entry.kind === 'skill');
248
+ const refusedMembers = outcome.refused.filter((entry) => entry.kind === 'member');
249
+ // Escaped, because a name reaches here from a guide's declared path and one
250
+ // carrying ANSI escapes could forge the lines after it (`display-path.ts`).
251
+ const refusalLine = ({ name, reason }) => ` ${displayFileName(name)} — ${reason}`;
252
+ if (refusedSkills.length > 0) {
253
+ lines.push(` ${withCount(refusedSkills.length, 'guide')} scoped to every repo ${refusedSkills.length === 1 ? 'was' : 'were'} not delivered to ${where}:`);
254
+ lines.push(...refusedSkills.map(refusalLine));
255
+ }
256
+ if (refusedMembers.length > 0) {
257
+ lines.push(` ${withCount(refusedMembers.length, 'file')} belonging to a delivered guide could not be written to ${where}:`);
258
+ lines.push(...refusedMembers.map(refusalLine));
259
+ }
260
+ // Named, because a removal from a home directory is the change a user most
261
+ // needs to hear about: the switch turned off, this machine opted out, or a
262
+ // guide stopped being delivered, and the skill left every session with it.
263
+ if (outcome.removed.length > 0) {
264
+ lines.push(` removed ${withCount(outcome.removed.length, 'file')} Mossbear had delivered to ${where}:`);
265
+ lines.push(...outcome.removed.map((path) => ` ${displayFileName(path)}`));
266
+ }
267
+ if (outcome.kept.length > 0) {
268
+ lines.push(` ${withCount(outcome.kept.length, 'file')} in ${where} ${outcome.kept.length === 1 ? 'was' : 'were'} kept:`);
269
+ for (const { path, reason } of outcome.kept) {
270
+ lines.push(` ${displayFileName(path)} — ${reason}`);
271
+ }
272
+ }
273
+ }
274
+ return lines;
275
+ }
276
+ export function formatArtifactsRetirementLines(result, options = {}) {
277
+ const lines = [];
278
+ for (const reason of result.deliveryRefusals ?? [])
279
+ lines.push(...wrapHanging(reason, ' = ', ' ').split('\n'));
280
+ if (result.stateUnreadable) {
281
+ // First line and, in this state, the only one — every other list is empty.
282
+ // Names the file and the code because the reader is standing at a terminal
283
+ // in the repo and that is what they need to go look at; says what was *not*
284
+ // done, so nothing is inferred from the silence that follows; and ends in
285
+ // the one action that clears it. No cause is named beyond the code: a
286
+ // permissions problem, a directory in the file's place and an I/O error all
287
+ // arrive here identically — naming one would be a cause this branch cannot
288
+ // distinguish.
289
+ lines.push(` couldn't read ${result.stateUnreadable.path} (${result.stateUnreadable.code}) — artifacts were not synced, so nothing was written over it; make the file readable and run \`mossbear refresh\``);
290
+ return lines;
291
+ }
292
+ lines.push(...globalDeliveryLines(result.globalDelivery));
293
+ if (result.globalRetired.length > 0) {
294
+ // Said once, in the pass that removed them. The sentence names what the
295
+ // directory was for and where the answer now lives, and does not say where
296
+ // each guide went: that depends on a consent this branch does not read.
297
+ lines.push(` removed ${withCount(result.globalRetired.length, 'file')} from ${MOSSBEAR_GLOBAL_DIR} — a guide scoped to every repo is no longer kept there, where nothing read it; \`mossbear status\` shows where each one is delivered:`);
298
+ lines.push(...listNames(result.globalRetired));
299
+ }
300
+ if (result.globalKept.length > 0) {
301
+ lines.push(` ${withCount(result.globalKept.length, 'file')} in ${MOSSBEAR_GLOBAL_DIR} ${result.globalKept.length === 1 ? 'was' : 'were'} kept:`);
302
+ for (const { path, reason } of result.globalKept) {
303
+ lines.push(` ${displayFileName(path)} — ${reason}`);
304
+ }
305
+ }
306
+ if (result.skillTwins) {
307
+ lines.push(...formatSkillTwinLines(result.skillTwins.results, result.skillTwins.retired));
308
+ }
309
+ const derived = withMirrorOutcome(result.aliasMirrors, 'derived');
310
+ if (derived.length > 0) {
311
+ // Says what it did and where the bytes came from: this is a write into a
312
+ // tracked file the reader did not ask for in this run, so "which file won"
313
+ // is the first thing they need — and the `git diff` that follows is theirs
314
+ // to read.
315
+ for (const entry of derived) {
316
+ lines.push(` rewrote ${displayFileName(entry.path)} from ${displayFileName(entry.source ?? '')} — they hold the same guide`);
317
+ }
318
+ }
319
+ for (const entry of withMirrorOutcome(result.aliasMirrors, 'held-uncommitted')) {
320
+ lines.push(` kept your ${displayFileName(entry.path)} — it has uncommitted changes, so it was not rewritten from ${displayFileName(entry.source ?? '')}`);
321
+ }
322
+ for (const entry of withMirrorOutcome(result.aliasMirrors, 'no-local-source')) {
323
+ // The divergent pair as it looks from here. Named rather than skipped: the
324
+ // files hold different rules and only the person who wrote them can say
325
+ // which is right.
326
+ lines.push(` left ${entry.path} as they are — these files hold one guide and differ, and neither an uncommitted edit nor git history shows which one to copy from${entry.error === undefined ? '' : ` (${entry.error})`}`);
327
+ }
328
+ for (const entry of withMirrorOutcome(result.aliasMirrors, 'several-edited')) {
329
+ lines.push(` left ${entry.path} as they are — these files hold one guide and more than one of them has been edited`);
330
+ }
331
+ for (const entry of withMirrorOutcome(result.aliasMirrors, 'failed')) {
332
+ lines.push(`${severityPrefix('failed')}could not rewrite ${displayFileName(entry.path)}${entry.error === undefined ? '' : ` — ${entry.error}`}`);
333
+ }
334
+ for (const entry of withMirrorOutcome(result.aliasMirrors, 'unsafe-path')) {
335
+ lines.push(`${severityPrefix('failed')}refused ${displayFileName(entry.path)}${entry.error === undefined ? '' : ` — ${entry.error}`}`);
336
+ }
337
+ if (result.claudeMdSwap?.outcome === 'swapped') {
338
+ // A write into a tracked file the reader did not ask for in this run, so it
339
+ // says what changed and why, in one line; the `git diff` is theirs to read.
340
+ lines.push(' replaced CLAUDE.md, a copy of AGENTS.md, with `@AGENTS.md` — Claude now reads AGENTS.md through it, and it no longer goes stale');
341
+ }
342
+ else if (result.claudeMdSwap?.outcome === 'held-uncommitted') {
343
+ lines.push(
344
+ // Both causes land here — an uncommitted edit, and git having no answer
345
+ // — so the line names what they share: git could not give the bytes back.
346
+ ' left CLAUDE.md as it is — it is a copy of AGENTS.md that Claude reads instead, and git could not give it back if replaced; replace it with the line `@AGENTS.md`');
347
+ }
348
+ else if (result.claudeMdSwap?.outcome === 'failed') {
349
+ lines.push(`${severityPrefix('failed')}could not replace CLAUDE.md with \`@AGENTS.md\`${result.claudeMdSwap.error === undefined ? '' : ` — ${result.claudeMdSwap.error}`}`);
350
+ }
351
+ if (result.gitFallback) {
352
+ // Said, rather than left to be inferred from an absence. The fallback is
353
+ // deliberate and it is today's behaviour — but a reader who believes
354
+ // uncommitted work is being held back, and is wrong about that, is worse off
355
+ // than one who never expected the rule to apply.
356
+ lines.push(' git could not report committed content here; delivery still protects tracked paths before writing');
357
+ }
358
+ if (result.trackedContext.length > 0) {
359
+ // Named as committed rather than as a mistake: a repo that committed these
360
+ // before the ignore rule existed did nothing wrong, and telling someone they
361
+ // misconfigured something they never configured is what
362
+ // `error-messaging.md` rules out. What they need is the sentence
363
+ // that says the files are duplicated and the command that stops it.
364
+ lines.push(` ${withCount(result.trackedContext.length, 'pulled artifact')} committed to this repo — already in your Mossbear account, so this history is a second copy that will go stale:`);
365
+ lines.push(...listNames(result.trackedContext));
366
+ // `--cached`, and the sentence says what that means, because the difference
367
+ // between this and `git rm` is the user's files. Mossbear never runs it: the
368
+ // command is offered, never taken.
369
+ lines.push(` stop committing them, keeping the files: git rm --cached -r ${MOSSBEAR_CONTEXT_DIR}`);
370
+ lines.push(' or declare a path with mossbear publish <path>; copies outside their home bundle or published path may become a new item');
371
+ }
372
+ if (result.retired.length > 0) {
373
+ lines.push(` removed ${withCount(result.retired.length, 'file')} outside the bundle folders, no longer in any subscribed bundle:`);
374
+ lines.push(...listNames(result.retired));
375
+ }
376
+ for (const path of result.retireFailed) {
377
+ lines.push(`${severityPrefix('failed')}could not remove ${displayFileName(path)} — remove it by hand.`);
378
+ }
379
+ if (result.releasedGitOwned.length > 0) {
380
+ // Said once, in the pass that stopped tracking these files, in the shape
381
+ // `strandedForeign` uses. What is true of all of them is that git delivers
382
+ // this path and Mossbear no longer maintains what is at it; what is *not*
383
+ // said is that they are inert, because some of them sit at discovery roots
384
+ // and are still read on every session — and it is not said that they do,
385
+ // because a mapped document at an ordinary tracked path does not. The
386
+ // branch cannot tell those apart, so the line names neither.
387
+ lines.push(` ${withCount(result.releasedGitOwned.length, 'file')} outside the bundle folders ${result.releasedGitOwned.length === 1 ? 'is' : 'are'} no longer in any subscribed bundle — left exactly as found, since git tracks this repo's files, and no longer tracked by Mossbear:`);
388
+ lines.push(...listNames(result.releasedGitOwned));
389
+ // `openPassMappings.applyRetirement` records suppression with each release,
390
+ // and its completion persists it before this result is returned. `rm` is
391
+ // capped the same way
392
+ // `listNames` caps the names above it: a hundred-file `rm` line is not
393
+ // more pasteable than a hundred-file list is more readable.
394
+ const width = terminalWidth();
395
+ const comment = "Mossbear recorded this, so `mossbear link` won't offer them back with these exact bytes — name one directly to adopt it fresh anyway. Mossbear will not remove them for you; when you are ready:";
396
+ for (const wrapped of wrapText(comment, Math.max(width - 6, MIN_WRAP_WIDTH))) {
397
+ lines.push(` ${wrapped}`);
398
+ }
399
+ const cleanupTargets = result.releasedGitOwned
400
+ .slice(0, ORPHAN_NAME_LIMIT)
401
+ .map((path) => shellQuotePosix(displayFileName(path)));
402
+ const cleanupMore = result.releasedGitOwned.length - cleanupTargets.length;
403
+ lines.push(...wrapCommandLine('rm --', cleanupTargets, width));
404
+ if (cleanupMore > 0)
405
+ lines.push(` # +${cleanupMore} more listed above`);
406
+ }
407
+ const rekeyed = result.rekeyed ?? [];
408
+ if (rekeyed.length > 0) {
409
+ lines.push(` ~ ${withCount(rekeyed.length, 'placement record')} now ${rekeyed.length === 1 ? 'names its' : 'name their'} guide by its new id`);
410
+ }
411
+ for (const entry of result.rekeyAmbiguous ?? []) {
412
+ lines.push(` ! ${displayFileName(entry.path)} names an id the server no longer uses`);
413
+ for (const wrapped of wrapText('More than one guide could be it, so the record was not changed.', Math.max(terminalWidth() - 4, MIN_WRAP_WIDTH))) {
414
+ lines.push(` ${wrapped}`);
415
+ }
416
+ }
417
+ for (const entry of result.relinked) {
418
+ lines.push(` followed ${displayFileName(entry.from)} → ${displayFileName(entry.to)} (moved locally; the mapping now points there)`);
419
+ }
420
+ for (const entry of result.relinkUnresolved) {
421
+ const detail = entry.reason === 'ambiguous'
422
+ ? `several files could be it (${(entry.candidates ?? []).map(displayFileName).join(', ')})`
423
+ : entry.reason === 'no-git'
424
+ ? 'this is not a git work tree, so there is nothing to search'
425
+ : entry.reason === 'unstaged-move'
426
+ ? // Named with its candidate, because it is almost always right and a
427
+ // bare "not found" would waste what we do know. Not adopted: git
428
+ // reports an untracked file the same way whether it appeared a
429
+ // second ago or a year ago, so the matching bytes are a
430
+ // coincidence this cannot rule out.
431
+ `${displayFileName((entry.candidates ?? [])[0] ?? '')} has the same content and may be it — git cannot say whether it is new, so confirm it`
432
+ : 'no moved or newly added file matches it';
433
+ lines.push(`${severityPrefix('degraded')}${displayFileName(entry.path)} is missing and was not rewritten — ${detail}.`);
434
+ lines.push(` point the mapping at its new home with: mossbear artifacts relink ${displayFileName(entry.path)} ${entry.reason === 'unstaged-move'
435
+ ? displayFileName((entry.candidates ?? [])[0] ?? '<path>')
436
+ : '<path>'}`);
437
+ }
438
+ if (result.keptOutOfDir.length > 0 && options.standing !== 'count') {
439
+ lines.push(` ${withCount(result.keptOutOfDir.length, 'file')} outside the bundle folders ${result.keptOutOfDir.length === 1 ? 'is' : 'are'} no longer in any subscribed bundle, kept, not safe to remove (edited locally, unreadable, or linked outside the repo):`);
440
+ lines.push(...listNames(result.keptOutOfDir));
441
+ }
442
+ if (result.keptUnprunedOutOfDir.length > 0) {
443
+ lines.push(` ${withCount(result.keptUnprunedOutOfDir.length, 'file')} outside the bundle folders ${result.keptUnprunedOutOfDir.length === 1 ? 'is' : 'are'} no longer in any subscribed bundle, kept (--no-prune):`);
444
+ lines.push(...listNames(result.keptUnprunedOutOfDir));
445
+ }
446
+ // Grouped by the bundle each mapping names, because that is the unit of the
447
+ // one action that resolves it — and an ungrouped list would repeat the same
448
+ // sentence once per file.
449
+ const unsubscribedByBundle = new Map();
450
+ for (const { path, bundle } of result.keptUnsubscribed) {
451
+ unsubscribedByBundle.set(bundle, [...(unsubscribedByBundle.get(bundle) ?? []), path]);
452
+ }
453
+ for (const [bundle, paths] of unsubscribedByBundle) {
454
+ // Not "your config is wrong": `mossbear pull --once` produces this on
455
+ // purpose, and a pull whose config write failed already warned at the time.
456
+ // Say what was kept and what makes these files sync again; the sync has no
457
+ // way to tell those two origins apart, so it names neither.
458
+ lines.push(` ${withCount(paths.length, 'file')} came from "${bundle}", which this repo does not subscribe to — kept, since a sync only sees what left the bundles it subscribes to:`);
459
+ lines.push(...listNames(paths));
460
+ // The picker, not `mossbear pull <label>`. A mapping records a *label*, and
461
+ // `resolveBundleByName` matches an exact id or an exact slug and nothing
462
+ // else (`bundle-by-name.ts:45-56`) — so a label the docs phase wrote as a
463
+ // suffixed `dirName` (`delivery.ts:92`) resolves to "no bundle named", and a
464
+ // bare slug two bundles share resolves to ambiguous. The mapping carries no
465
+ // id to print instead, so naming a command built from the label would be
466
+ // advice that errors in exactly the collision cases this report exists for.
467
+ lines.push(' to sync them again: mossbear pull, then pick it from the list');
468
+ }
469
+ return lines;
470
+ }
471
+ /** How many names to print before summarizing the rest. */
472
+ const ORPHAN_NAME_LIMIT = 10;
473
+ /** Never wrap a comment narrower than this, however small the terminal reports. */
474
+ const MIN_WRAP_WIDTH = 20;
475
+ /**
476
+ * Name the files, capped — but say how many were withheld, never truncate in
477
+ * silence.
478
+ */
479
+ function withMirrorOutcome(mirrors, outcome) {
480
+ return mirrors.filter((entry) => entry.outcome === outcome);
481
+ }
482
+ function listNames(names) {
483
+ const shown = names
484
+ .slice(0, ORPHAN_NAME_LIMIT)
485
+ .map((name) => ` ${displayFileName(name)}`);
486
+ const rest = names.length - shown.length;
487
+ return rest > 0 ? [...shown, ` …and ${rest} more`] : shown;
488
+ }
489
+ /**
490
+ * Quote a path for a POSIX shell, so a pasted cleanup command cannot be
491
+ * talked into deleting or running anything else.
492
+ *
493
+ * `displayFileName` only neutralizes control characters — it leaves a space,
494
+ * a leading `-`, or a `$(...)` untouched, and any of those in an otherwise
495
+ * ordinary repo-relative filename would still reach the shell raw once
496
+ * printed bare into a suggested `rm` line. Single-quoting is what closes
497
+ * that: nothing inside single quotes is special to a POSIX shell except the
498
+ * quote character itself, escaped here by closing, inserting an escaped
499
+ * quote, and reopening.
500
+ */
501
+ export function shellQuotePosix(path) {
502
+ return `'${path.replace(/'/g, `'\\''`)}'`;
503
+ }
504
+ /**
505
+ * Wrap a shell command across lines a terminal will not mangle, one whole
506
+ * argument per break and a trailing `\` continuation — never a hard cut
507
+ * inside a quoted path, which `wrapText`'s whitespace-only splitting would
508
+ * risk for the sentence beside it but must not risk for a command a reader
509
+ * pastes verbatim.
510
+ */
511
+ function wrapCommandLine(head, args, width) {
512
+ const indent = ' ';
513
+ const continued = `${indent} `;
514
+ const lines = [];
515
+ let current = `${indent}${head}`;
516
+ for (const arg of args) {
517
+ const candidate = `${current} ${arg}`;
518
+ if (current === `${indent}${head}` || displayWidth(candidate) <= width) {
519
+ current = candidate;
520
+ }
521
+ else {
522
+ lines.push(`${current} \\`);
523
+ current = `${continued}${arg}`;
524
+ }
525
+ }
526
+ lines.push(current);
527
+ return lines;
528
+ }
529
+ /** Docs with a given outcome. */
530
+ function withOutcome(docs, outcome) {
531
+ return docs.filter((doc) => doc.outcome === outcome);
532
+ }
533
+ /**
534
+ * One legible block per bundle for the sync output (Planning Principle 9 — what
535
+ * moved is never ambiguous). Failures read as warnings; a successful sync says
536
+ * how many files moved in each direction, and names everything that needs the
537
+ * user: conflicts, refusals, and files the bundle no longer contains.
538
+ */
539
+ /**
540
+ * True when {@link formatArtifactsSyncLine} would say only that nothing moved.
541
+ *
542
+ * What `mossbear refresh --quiet` uses to tell a receipt from a report. A bundle
543
+ * whose every doc is `in-sync` prints a headline and nothing under it; the
544
+ * moment any doc was written, pushed, refused, held or failed, the formatter
545
+ * adds a count or a comment beneath, and that is the run's account of a change in
546
+ * this repo.
547
+ *
548
+ * Two checks, because the formatter reports in two places. The headline counts
549
+ * doc outcomes, so those are enumerated: `in-sync`, and a `git-owned` doc with
550
+ * no error — the one silent outcome, since it names the ordinary case of a
551
+ * project guide sitting in its own repo. Everything else — kept, pruned,
552
+ * unmanaged and stranded files, skipped orphan checks, conflicts — lands as a
553
+ * line *under* the headline, and there are a dozen such branches. Rather than
554
+ * list each field and drift the first time one is added, the second check asks
555
+ * the formatter itself: a result that renders to more than the headline is
556
+ * not routine, whatever put the extra line there.
557
+ */
558
+ export function artifactsSyncResultIsRoutine(result, options = {}) {
559
+ if (result.error !== undefined)
560
+ return false;
561
+ if (result.truncated)
562
+ return false;
563
+ const headlineOnly = result.docs.every((doc) => doc.outcome === 'in-sync' ||
564
+ (doc.outcome === 'git-owned' && doc.error === undefined) ||
565
+ (doc.outcome === 'out-of-scope' && options.standing === 'count'));
566
+ return headlineOnly && !formatArtifactsSyncLine(result, options).includes('\n');
567
+ }
568
+ /**
569
+ * The one line that stands for every standing list a sync left out under
570
+ * `standing: 'count'`, or nothing when there are none.
571
+ *
572
+ * **Names no command.** Every command that would list these sets in full
573
+ * either may write to the account (`refresh` publishes from the published
574
+ * branch on every run) or changes this repo's subscriptions (`pull`), and the
575
+ * reader here is usually an agent. The full lists still print wherever a person
576
+ * runs a sync with `--verbose`; this line only says they exist and that
577
+ * nothing about them changed.
578
+ */
579
+ export function formatStandingCountLine(report, width = terminalWidth()) {
580
+ const homeOnly = report.results.reduce((sum, result) => sum + (result.error ? 0 : withOutcome(result.docs, 'out-of-scope').length), 0);
581
+ const kept = report.keptOutOfDir.length +
582
+ report.results.reduce((sum, result) => sum + (result.error ? 0 : result.orphansKept.length), 0);
583
+ const parts = [];
584
+ if (homeOnly > 0) {
585
+ parts.push(`${withCount(homeOnly, 'artifact')} ${homeOnly === 1 ? 'belongs' : 'belong'} to your home directory, not this repo`);
586
+ }
587
+ if (kept > 0) {
588
+ parts.push(`${withCount(kept, 'file')} no longer in a bundle ${kept === 1 ? 'was' : 'were'} kept`);
589
+ }
590
+ if (parts.length === 0)
591
+ return [];
592
+ return wrapHanging(`left as before: ${parts.join('; ')}`, ' = ', ' ', width).split('\n');
593
+ }
594
+ export function formatArtifactsSyncLine(result, options = {}) {
595
+ if (result.error) {
596
+ const failed = [
597
+ `${severityPrefix('failed')}bundle "${result.bundle}" — ${result.error} — skipping.`,
598
+ ];
599
+ // A bundle can fail *after* writing some of its docs — the pull succeeds,
600
+ // several items materialize, and a later one throws. Returning here named
601
+ // none of them, so `mossbear refresh` reported only "skipping" for a run that had
602
+ // already changed files in the repo. Raised by Codex on PR #565.
603
+ if (result.wroteOutsideDir.length > 0) {
604
+ failed.push(` ${withCount(result.wroteOutsideDir.length, 'file')} ${result.wroteOutsideDir.length === 1 ? 'was' : 'were'} already written at their own path before it failed:`);
605
+ failed.push(...listNames(result.wroteOutsideDir));
606
+ }
607
+ return failed.join('\n');
608
+ }
609
+ const created = withOutcome(result.docs, 'created').length;
610
+ const pulled = withOutcome(result.docs, 'pulled').length;
611
+ const pushedFromCommitted = withOutcome(result.docs, 'pushed-committed');
612
+ const pushed = withOutcome(result.docs, 'pushed').length + pushedFromCommitted.length;
613
+ const inSync = withOutcome(result.docs, 'in-sync').length;
614
+ const skipped = result.items - result.docs.length;
615
+ const moved = [];
616
+ if (created > 0)
617
+ moved.push(`${created} new`);
618
+ if (pulled > 0)
619
+ moved.push(`${pulled} updated`);
620
+ if (pushed > 0)
621
+ moved.push(`${pushed} pushed`);
622
+ if (inSync > 0)
623
+ moved.push(`${inSync} unchanged`);
624
+ const skippedNote = skipped > 0
625
+ ? ` (${withCount(skipped, 'artifact')} without text content skipped, e.g. assets)`
626
+ : '';
627
+ const truncatedNote = result.truncated
628
+ ? ` — comment: hit the ${MAX_BUNDLE_PULL}-artifact limit, older artifacts may be unpulled`
629
+ : '';
630
+ const lines = [
631
+ ` synced "${result.bundle}" → ${result.dir}: ${moved.length > 0 ? moved.join(', ') : 'nothing to do'}${skippedNote}${truncatedNote}`,
632
+ ];
633
+ if (result.wroteOutsideDir.length > 0) {
634
+ // The `→ <dir>` above is this bundle's folder, and a doc at its own declared
635
+ // path did not go there. Name those files: created and pulled docs are
636
+ // otherwise only counted, so the destination line would be the only thing
637
+ // the user is told about where the write landed, and it would be wrong.
638
+ lines.push(` ${result.wroteOutsideDir.length} of them landed at their own path, outside this folder — written by this sync, not by you:`);
639
+ lines.push(...listNames(result.wroteOutsideDir));
640
+ // Said because the commonest reader is an agent mid-task, and these are the
641
+ // files that reach it as unexplained entries in `git status`. Naming where
642
+ // they came from is what stops the two wrong answers: sweeping them into an
643
+ // unrelated commit, or reverting content someone else published.
644
+ lines.push(' they came from the bundle, so they are not part of your own change — commit them on their own, or leave them');
645
+ }
646
+ const conflicted = withOutcome(result.docs, 'both-changed');
647
+ if (conflicted.length > 0) {
648
+ lines.push(` ${withCount(conflicted.length, 'artifact')} changed both locally and on the server — left untouched:`);
649
+ lines.push(...listNames(conflicted.map((doc) => doc.path)));
650
+ // **The two resolutions are not reachable from the same verb.** `remote`
651
+ // takes the server's copy, which any delivery may do; `local` publishes
652
+ // yours, which only `complete` does — every other operation refuses it by
653
+ // name (`lifecycle/operations.ts`, the `--conflict local` gate). One
654
+ // line naming both against one command sent the reader to a combination the
655
+ // CLI rejects, which is the remedy-that-does-nothing failure this repo's
656
+ // error-messaging rules exist to prevent.
657
+ lines.push(" take the server's copy: mossbear refresh --conflict remote", ' send yours instead: mossbear complete --conflict local');
658
+ }
659
+ const unverified = withOutcome(result.docs, 'unverified');
660
+ if (unverified.length > 0) {
661
+ lines.push(` ${withCount(unverified.length, 'artifact')} ${unverified.length === 1 ? 'differs' : 'differ'} from the last synced copy but could not be checked against the artifact's full history — left untouched in both directions:`);
662
+ lines.push(...listNames(unverified.map((doc) => doc.path)));
663
+ lines.push(' resolve with: mossbear refresh --conflict remote (or edit the artifact in the dashboard)');
664
+ }
665
+ const notPushed = withOutcome(result.docs, 'not-pushed');
666
+ if (notPushed.length > 0) {
667
+ lines.push(` ${withCount(notPushed.length, 'locally-edited artifact')} ${notPushed.length === 1 ? 'was' : 'were'} left as found — this run does not publish:`);
668
+ lines.push(...listNames(notPushed.map((doc) => doc.path)));
669
+ // Names a remedy that works. There is no flag any more: an edit travels
670
+ // back when the session ends, which is `mossbear complete` and only it
671
+ // (`lifecycle/operations.ts` → the contract table), and a line still
672
+ // offering `--push-docs` would send the reader after an argument the CLI
673
+ // rejects.
674
+ lines.push(' they travel back when this session ends: mossbear complete');
675
+ }
676
+ // Named, not just counted like every other `pushed` doc. Until Decision 14 an
677
+ // edit to one of these was refused with "commit them and re-run", a remedy its
678
+ // author often could not reach; saying where the bytes came from is what
679
+ // replaces that sentence.
680
+ //
681
+ // **The reason says "Mossbear keeps these", not "git does not track these",
682
+ // and the difference is a rule.** This branch never asks git — the classifier
683
+ // decides on the path alone — so tracked-ness is a cause it cannot
684
+ // distinguish, and this repo's error-messaging rules forbid naming one.
685
+ // It is not hypothetical either: a repo that force-added its documents
686
+ // before the ignore rule shipped still has them in the index, which is the
687
+ // population the tracked-file sweep below exists to find. Their edit publishes
688
+ // from disk exactly the same way, so "an edit publishes without a commit" is
689
+ // true of every file this line can name, and "git does not track these" is
690
+ // false of some of them.
691
+ //
692
+ // The classifier decides which ones, the same one the push rule asks
693
+ // (`sync-plan.ts` → `committedPushBody`), so the report cannot come to name a
694
+ // different set of files than the rule acted on. That holds despite this call
695
+ // passing one fewer argument — a `ArtifactResult` carries the path it landed at and
696
+ // not the item's root — because `record` is settled on the path alone, which
697
+ // `ArtifactRecord` says is the point rather than an accident.
698
+ const pushedFromDisk = withOutcome(result.docs, 'pushed').filter((doc) => classifyArtifactPlacement({ storedPath: doc.path }).record === 'server');
699
+ if (pushedFromDisk.length > 0) {
700
+ lines.push(` ${pushedFromDisk.length} of those were published from the file on disk — Mossbear keeps these, so an edit publishes without a commit:`);
701
+ lines.push(...listNames(pushedFromDisk.map((doc) => doc.path)));
702
+ }
703
+ if (pushedFromCommitted.length > 0) {
704
+ lines.push(` ${pushedFromCommitted.length} of those were published from their committed version — the newer edits on disk stayed here:`);
705
+ lines.push(...listNames(pushedFromCommitted.map((doc) => doc.path)));
706
+ lines.push(' commit them and re-run to publish those edits too');
707
+ }
708
+ const uncommitted = withOutcome(result.docs, 'uncommitted');
709
+ if (uncommitted.length > 0) {
710
+ lines.push(` ${withCount(uncommitted.length, 'artifact')} ${uncommitted.length === 1 ? 'has' : 'have'} changes git has not recorded — left exactly as found, in both directions:`);
711
+ lines.push(...listNames(uncommitted.map((doc) => doc.path)));
712
+ lines.push(' commit them and re-run — Mossbear exchanges committed content');
713
+ }
714
+ const unpushable = withOutcome(result.docs, 'unpushable');
715
+ if (unpushable.length > 0) {
716
+ lines.push(` ${withCount(unpushable.length, 'locally-edited artifact')} cannot be pushed — the artifact carries no version, so a safe update is impossible. Edit ${unpushable.length === 1 ? 'it' : 'them'} in the dashboard instead:`);
717
+ lines.push(...listNames(unpushable.map((doc) => doc.path)));
718
+ }
719
+ for (const invalid of withOutcome(result.docs, 'invalid-path')) {
720
+ lines.push(`${severityPrefix('failed', ' ')}guide "${displayFileName(invalid.path)}" was not materialized — ${invalid.error ?? 'unsafe projection path'}`);
721
+ }
722
+ const outOfScope = withOutcome(result.docs, 'out-of-scope');
723
+ if (outOfScope.length > 0 && options.standing !== 'count') {
724
+ lines.push(` ${withCount(outOfScope.length, 'artifact')} ${outOfScope.length === 1 ? 'belongs' : 'belong'} to your home directory, not this repo, and ${outOfScope.length === 1 ? 'was' : 'were'} not materialized here:`);
725
+ lines.push(...listNames(outOfScope.map((doc) => doc.path)));
726
+ lines.push(' edit them where they live (under your home directory) — a copy in the repo would fork them the moment you changed it');
727
+ }
728
+ // Only the ones carrying a reason. A `git-owned` skip is silent by design —
729
+ // it names the ordinary case, a project guide sitting correctly in its own
730
+ // repo — but the planner attaches an error when the run asked to publish, and
731
+ // an explicit request must never be dropped without a word.
732
+ const gitOwnedRefused = withOutcome(result.docs, 'git-owned').filter((doc) => doc.error !== undefined);
733
+ if (gitOwnedRefused.length > 0) {
734
+ lines.push(` ${withCount(gitOwnedRefused.length, 'edit')} ${gitOwnedRefused.length === 1 ? 'was' : 'were'} not published — ${gitOwnedRefused.length === 1 ? 'this file is' : 'these files are'} delivered by git, not by sync:`);
735
+ lines.push(...listNames(gitOwnedRefused.map((doc) => doc.path)));
736
+ lines.push(' commit the edit: it publishes once it lands on the published branch, and `mossbear publish` sends it sooner');
737
+ lines.push(" or `mossbear promote` to take the server's copy into this repo instead");
738
+ }
739
+ const readOnlyRefused = withOutcome(result.docs, 'read-only');
740
+ if (readOnlyRefused.length > 0) {
741
+ lines.push(` ${withCount(readOnlyRefused.length, 'edit')} ${readOnlyRefused.length === 1 ? 'was' : 'were'} not published — ${readOnlyRefused.length === 1 ? 'this artifact comes' : 'these artifacts come'} from a bundle another workspace publishes, delivered read-only:`);
742
+ lines.push(...listNames(readOnlyRefused.map((doc) => doc.path)));
743
+ lines.push(' your local copy is left exactly as it is');
744
+ }
745
+ const notHomeRepo = withOutcome(result.docs, 'not-home-repo');
746
+ if (notHomeRepo.length > 0) {
747
+ lines.push(` ${withCount(notHomeRepo.length, 'edit')} ${notHomeRepo.length === 1 ? 'was' : 'were'} not published — ${notHomeRepo.length === 1 ? 'this artifact is' : 'these artifacts are'} published from their bundle's home repository:`);
748
+ lines.push(...listNames(notHomeRepo.map((doc) => doc.path)));
749
+ lines.push(' open a pull request in that repository; your local copy is left exactly as it is');
750
+ }
751
+ const gitPublished = withOutcome(result.docs, 'git-published');
752
+ if (gitPublished.length > 0) {
753
+ lines.push(` ${withCount(gitPublished.length, 'edit')} ${gitPublished.length === 1 ? 'was' : 'were'} not published — ${gitPublished.length === 1 ? 'this artifact is' : 'these artifacts are'} published from a git repository:`);
754
+ lines.push(...listNames(gitPublished.map((doc) => doc.path)));
755
+ lines.push(' make the change there, commit it, and `mossbear publish` it from that repo; your local copy is left exactly as it is');
756
+ }
757
+ const placementConflicted = withOutcome(result.docs, 'placement-conflict');
758
+ if (placementConflicted.length > 0) {
759
+ lines.push(` ${withCount(placementConflicted.length, 'artifact')} ${placementConflicted.length === 1 ? 'has' : 'have'} two placement records at different paths — left untouched until one is removed:`);
760
+ lines.push(...listNames(placementConflicted.map((doc) => doc.path)));
761
+ lines.push(' edit .mossbear/placement.jsonl (or .mossbear/context/placement.jsonl) and delete the line naming the wrong path, then re-sync');
762
+ }
763
+ const tooLarge = withOutcome(result.docs, 'too-large');
764
+ if (tooLarge.length > 0) {
765
+ lines.push(` ${withCount(tooLarge.length, 'locally-edited artifact')} ${tooLarge.length === 1 ? 'exceeds' : 'exceed'} the ${Math.floor(MAX_CONTEXT_CONTENT_BYTES / 1024)} KB content limit and ${tooLarge.length === 1 ? 'was' : 'were'} not pushed:`);
766
+ lines.push(...listNames(tooLarge.map((doc) => doc.path)));
767
+ }
768
+ for (const failed of withOutcome(result.docs, 'push-failed')) {
769
+ lines.push(`${severityPrefix('failed', ' ')}could not push ${displayFileName(failed.path)} — ${failed.error ?? 'unknown error'}`);
770
+ }
771
+ if (result.orphanCheck === 'skipped-truncated') {
772
+ lines.push(` bundle hit the ${MAX_BUNDLE_PULL}-artifact ceiling — orphan detection skipped (cannot tell removed from unreturned)`);
773
+ }
774
+ else if (result.orphanCheck === 'skipped-unreadable') {
775
+ lines.push(`${severityPrefix('degraded', ' ')}could not read ${result.dir} — orphan detection skipped (files removed upstream may still be on disk)`);
776
+ }
777
+ else if (result.orphanCheck === 'skipped-unsafe-path') {
778
+ lines.push(`${severityPrefix('degraded', ' ')}${result.dir} resolves outside this repo's .mossbear/context — orphan detection skipped (refusing to sweep a linked directory)`);
779
+ }
780
+ if (result.orphansKept.length > 0 && options.standing !== 'count') {
781
+ lines.push(` ${withCount(result.orphansKept.length, 'file')} no longer in the bundle, kept, not safe to remove (edited locally, unreadable, or linked outside the repo):`);
782
+ lines.push(...listNames(result.orphansKept));
783
+ }
784
+ if (result.pruned.length > 0) {
785
+ lines.push(` removed ${withCount(result.pruned.length, 'file')} no longer in the bundle:`);
786
+ lines.push(...listNames(result.pruned));
787
+ }
788
+ if (result.keptUnpruned.length > 0) {
789
+ // Removal is the default, so reaching here means --no-prune: say the
790
+ // files were kept deliberately rather than pointing at a flag to run.
791
+ lines.push(` ${withCount(result.keptUnpruned.length, 'file')} no longer in the bundle, kept (--no-prune):`);
792
+ lines.push(...listNames(result.keptUnpruned));
793
+ }
794
+ if (result.unmanaged.length > 0) {
795
+ // Named, not warned about, and never acted on: the directory is the user's
796
+ // to put files in. Saying so is what keeps "Mossbear manages this folder" from
797
+ // being read as "Mossbear owns everything in it".
798
+ lines.push(` ${withCount(result.unmanaged.length, 'file')} in this folder ${result.unmanaged.length === 1 ? 'is' : 'are'} not from the bundle — left alone:`);
799
+ lines.push(...listNames(result.unmanaged));
800
+ }
801
+ if (result.strandedForeign.length > 0) {
802
+ // Said once, in the pass that also stopped tracking these files. The line
803
+ // names what is true — the guide lives in another repo — and what the user
804
+ // can do about it, which is to delete a copy nothing here maintains any
805
+ // more. It must not say the files are inert: they sit at discovery roots,
806
+ // so every agent in this repo still reads them, and that is the whole
807
+ // reason the line exists.
808
+ lines.push(` ${withCount(result.strandedForeign.length, 'file')} here ${result.strandedForeign.length === 1 ? 'is a copy' : 'are copies'} of a guide that belongs to a different repo — left exactly as found, and no longer tracked:`);
809
+ lines.push(...listNames(result.strandedForeign));
810
+ lines.push(' delete them when you are ready — agents in this repo still read them, and nothing keeps them up to date now');
811
+ }
812
+ if (result.strandedLiteral.length > 0) {
813
+ // Said once, in the pass that stopped tracking these files. The document is
814
+ // still delivered — the line says where — so what is left for the user is
815
+ // only the old copy, which is theirs to keep or delete.
816
+ lines.push(` ${withCount(result.strandedLiteral.length, 'file')} here ${result.strandedLiteral.length === 1 ? 'is an old copy' : 'are old copies'} of an artifact this repo is not the home of — left exactly as found, and no longer tracked:`);
817
+ lines.push(...listNames(result.strandedLiteral));
818
+ lines.push(' the artifact itself now lands under .mossbear/context/ instead — delete the old copy whenever you like');
819
+ }
820
+ if (result.strandedTwins.length > 0) {
821
+ // Named and left alone. The two ways a repo ends up with one of these — the
822
+ // guide's scope was changed, or an older CLI wrote a repo copy of a guide
823
+ // that was already global — are indistinguishable from here, so the line
824
+ // names neither: error copy must never state a cause the branch cannot
825
+ // distinguish. Nor does it say where the guide is kept now: since
826
+ // `global-delivery-dual-write-close` that depends on a consent this
827
+ // renderer does not read, and for a user who declined, this twin may be
828
+ // the only copy on the machine. It says what is true in every case — the
829
+ // sync no longer maintains this file — and where the answer lives.
830
+ lines.push(` ${withCount(result.strandedTwins.length, 'file')} ${result.strandedTwins.length === 1 ? 'is an old copy' : 'are old copies'} of a guide that is no longer delivered here — left exactly as found:`);
831
+ lines.push(...listNames(result.strandedTwins));
832
+ // **Never "nothing reads them".** They sit at a discovery root, so every
833
+ // agent in this repo still loads them — that is the whole reason this line
834
+ // exists, and telling the user they are inert is what would leave outdated
835
+ // guidance steering their sessions.
836
+ lines.push(' your agents here still read them, and nothing here keeps them up to date — `mossbear status` shows where the guide is delivered now; delete them whenever you like; Mossbear will not remove a file from your repo for you');
837
+ }
838
+ if (result.pruneFailed.length > 0) {
839
+ lines.push(`${severityPrefix('failed', ' ')}could not remove ${withCount(result.pruneFailed.length, 'file')}:`);
840
+ lines.push(...listNames(result.pruneFailed));
841
+ }
842
+ if (result.mutedArtifacts.length > 0) {
843
+ lines.push(` ${withCount(result.mutedArtifacts.length, 'artifact')} you muted ${result.mutedArtifacts.length === 1 ? 'was' : 'were'} not delivered:`);
844
+ lines.push(...listNames(result.mutedArtifacts));
845
+ }
846
+ if (result.migrateFailed.length > 0) {
847
+ lines.push(`${severityPrefix('failed', ' ')}could not move ${withCount(result.migrateFailed.length, 'guide file')} out of this folder, so ${result.migrateFailed.length === 1 ? 'it is' : 'they are'} not being read as guidance yet — remove ${result.migrateFailed.length === 1 ? 'it' : 'them'} by hand and re-sync:`);
848
+ lines.push(...listNames(result.migrateFailed));
849
+ }
850
+ return lines.join('\n');
851
+ }
191
852
  //# sourceMappingURL=sync-report.js.map