opencode-swarm 7.116.0 → 7.117.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 (52) hide show
  1. package/.opencode/skills/commit-pr/SKILL.md +60 -579
  2. package/dist/cli/{curator-drift-c0by7063.js → curator-drift-7p2ky1th.js} +2 -2
  3. package/dist/cli/{curator-7s5yw6hw.js → curator-fr2m5hna.js} +13 -13
  4. package/dist/cli/{curator-llm-factory-x96dr0zf.js → curator-llm-factory-m0kvna8n.js} +13 -13
  5. package/dist/cli/{evidence-summary-service-ef6kgtev.js → evidence-summary-service-bwt6drb3.js} +5 -5
  6. package/dist/cli/{gate-evidence-thqt0beq.js → gate-evidence-j2m4cd85.js} +3 -2
  7. package/dist/cli/{guardrail-explain-kwqfkwch.js → guardrail-explain-xjgk822d.js} +14 -14
  8. package/dist/cli/{hive-promoter-rkkx40qv.js → hive-promoter-zpk5jmx0.js} +13 -13
  9. package/dist/cli/{index-bbsaxnj5.js → index-0pfqcjp6.js} +4 -0
  10. package/dist/cli/{index-qgeeyy75.js → index-4f4zv8pb.js} +29 -7
  11. package/dist/cli/{index-a6f8b0vn.js → index-5bcrp3bc.js} +1 -1
  12. package/dist/cli/{index-81vzywh3.js → index-abjjn4yh.js} +1 -1
  13. package/dist/cli/{index-8bvh0qfa.js → index-af94ke83.js} +3 -3
  14. package/dist/cli/{index-k5ey429j.js → index-aws8yhwq.js} +7 -7
  15. package/dist/cli/{index-jyetmzcn.js → index-c9m5skgs.js} +3 -3
  16. package/dist/cli/{index-3yh67t1h.js → index-dc3j6jmk.js} +5 -4
  17. package/dist/cli/{index-jtqkh8jf.js → index-fsrp8wp3.js} +10 -1
  18. package/dist/cli/{index-s385axt1.js → index-hskmya46.js} +3 -3
  19. package/dist/cli/{index-wh8949ef.js → index-kzj3fp7c.js} +3 -3
  20. package/dist/cli/{index-tvgvb5pa.js → index-n3sm9ewn.js} +2 -2
  21. package/dist/cli/{index-3b8n3dbd.js → index-pgtqxat4.js} +14 -14
  22. package/dist/cli/{index-me46ffm2.js → index-vkdr12ek.js} +1700 -936
  23. package/dist/cli/{index-cnrhj56z.js → index-xdsd2hma.js} +6 -6
  24. package/dist/cli/index.js +13 -13
  25. package/dist/cli/{knowledge-escalator-0bq62d34.js → knowledge-escalator-bmk725p4.js} +6 -6
  26. package/dist/cli/{knowledge-events-cwwky393.js → knowledge-events-px14n75v.js} +4 -3
  27. package/dist/cli/{knowledge-store-q8x4h82m.js → knowledge-store-z9znvtn2.js} +4 -4
  28. package/dist/cli/{knowledge-validator-zr0djm02.js → knowledge-validator-7r5t821g.js} +5 -5
  29. package/dist/cli/{pending-delegations-rr9x47rd.js → pending-delegations-9cn17983.js} +2 -2
  30. package/dist/cli/{pr-subscriptions-cny2jz2d.js → pr-subscriptions-8a6jwek2.js} +3 -3
  31. package/dist/cli/{skill-generator-mz267btk.js → skill-generator-4d3w8sqt.js} +7 -7
  32. package/dist/commands/close.d.ts +12 -0
  33. package/dist/commands/link.d.ts +7 -4
  34. package/dist/commands/registry.d.ts +6 -6
  35. package/dist/commands/reset-backup.d.ts +32 -0
  36. package/dist/commands/reset-session.d.ts +2 -0
  37. package/dist/commands/reset.d.ts +9 -0
  38. package/dist/commands/unlink.d.ts +12 -5
  39. package/dist/evidence/task-file.d.ts +7 -0
  40. package/dist/hooks/knowledge-events.d.ts +2 -0
  41. package/dist/hooks/knowledge-link.d.ts +31 -4
  42. package/dist/index.js +240 -229
  43. package/dist/knowledge/cohort-identity.d.ts +103 -0
  44. package/dist/knowledge/config-fingerprint.d.ts +57 -0
  45. package/dist/knowledge/family-manifest.d.ts +50 -0
  46. package/dist/knowledge/family-migration.d.ts +109 -0
  47. package/dist/knowledge/identity.d.ts +12 -2
  48. package/dist/knowledge/index.d.ts +1 -0
  49. package/dist/services/knowledge-diagnostics.d.ts +27 -0
  50. package/dist/services/status-service.d.ts +13 -0
  51. package/dist/utils/swarm-artifact-cache.d.ts +13 -0
  52. package/package.json +1 -1
@@ -12,10 +12,7 @@ import {
12
12
  import {
13
13
  readSwarmFileAsync,
14
14
  validateSwarmPath
15
- } from "./index-wh8949ef.js";
16
- import {
17
- readCachedParsedFile
18
- } from "./index-jtqkh8jf.js";
15
+ } from "./index-kzj3fp7c.js";
19
16
  import {
20
17
  criticalWarn,
21
18
  error,
@@ -27,10 +24,10 @@ import {
27
24
  readTaskEvidence,
28
25
  readTaskEvidenceRaw,
29
26
  sanitizeTaskId
30
- } from "./index-81vzywh3.js";
27
+ } from "./index-abjjn4yh.js";
31
28
  import {
32
29
  atomicWriteFile
33
- } from "./index-bbsaxnj5.js";
30
+ } from "./index-0pfqcjp6.js";
34
31
  import {
35
32
  ZodError,
36
33
  exports_external
@@ -38,6 +35,9 @@ import {
38
35
  import {
39
36
  withEvidenceLock
40
37
  } from "./index-42cx6g2h.js";
38
+ import {
39
+ readCachedParsedFile
40
+ } from "./index-fsrp8wp3.js";
41
41
  import {
42
42
  emit
43
43
  } from "./index-q2rrv0cy.js";
package/dist/cli/index.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  getPluginLockFilePaths,
8
8
  package_default,
9
9
  resolveCommand
10
- } from "./index-me46ffm2.js";
10
+ } from "./index-vkdr12ek.js";
11
11
  import"./index-nprawcc0.js";
12
12
  import"./index-8j5d3ytd.js";
13
13
  import"./index-c8s9a3zh.js";
@@ -15,32 +15,32 @@ import"./index-m7hc7nn7.js";
15
15
  import {
16
16
  DEFAULT_AGENT_CONFIGS
17
17
  } from "./index-nvc0nsvg.js";
18
- import"./index-cnrhj56z.js";
18
+ import"./index-xdsd2hma.js";
19
19
  import"./index-scww5b77.js";
20
20
  import"./index-4905hd2m.js";
21
- import"./index-a6f8b0vn.js";
22
- import"./index-s385axt1.js";
23
- import"./index-jyetmzcn.js";
24
- import"./index-8bvh0qfa.js";
25
- import"./index-3yh67t1h.js";
26
- import"./index-k5ey429j.js";
21
+ import"./index-5bcrp3bc.js";
22
+ import"./index-hskmya46.js";
23
+ import"./index-c9m5skgs.js";
24
+ import"./index-af94ke83.js";
25
+ import"./index-dc3j6jmk.js";
26
+ import"./index-aws8yhwq.js";
27
27
  import"./index-bfwt3abw.js";
28
- import"./index-qgeeyy75.js";
28
+ import"./index-4f4zv8pb.js";
29
29
  import"./index-vxv732ex.js";
30
30
  import"./index-8fwhhayc.js";
31
31
  import"./index-q1exe2b3.js";
32
32
  import"./index-n6fa2hhk.js";
33
33
  import"./index-rdwfqhp7.js";
34
- import"./index-wh8949ef.js";
35
- import"./index-jtqkh8jf.js";
34
+ import"./index-kzj3fp7c.js";
36
35
  import"./index-5e4e2hvv.js";
37
36
  import"./index-p0arc26j.js";
38
37
  import"./index-zgwm4ryv.js";
39
38
  import"./index-dqh3zhhc.js";
40
- import"./index-81vzywh3.js";
41
- import"./index-bbsaxnj5.js";
39
+ import"./index-abjjn4yh.js";
40
+ import"./index-0pfqcjp6.js";
42
41
  import"./index-293f68mj.js";
43
42
  import"./index-42cx6g2h.js";
43
+ import"./index-fsrp8wp3.js";
44
44
  import"./index-q2rrv0cy.js";
45
45
  import"./index-vvk2g744.js";
46
46
  import"./index-qe3v54nb.js";
@@ -8,15 +8,15 @@ import {
8
8
  maybeEscalateOnViolation,
9
9
  maybeQuarantineOnContradiction,
10
10
  readRecentEscalations
11
- } from "./index-8bvh0qfa.js";
12
- import"./index-3yh67t1h.js";
13
- import"./index-k5ey429j.js";
11
+ } from "./index-af94ke83.js";
12
+ import"./index-dc3j6jmk.js";
13
+ import"./index-aws8yhwq.js";
14
14
  import"./index-bfwt3abw.js";
15
- import"./index-qgeeyy75.js";
16
- import"./index-jtqkh8jf.js";
15
+ import"./index-4f4zv8pb.js";
17
16
  import"./index-zgwm4ryv.js";
18
- import"./index-bbsaxnj5.js";
17
+ import"./index-0pfqcjp6.js";
19
18
  import"./index-42cx6g2h.js";
19
+ import"./index-fsrp8wp3.js";
20
20
  import"./index-q2rrv0cy.js";
21
21
  import"./index-vvk2g744.js";
22
22
  import"./index-qe3v54nb.js";
@@ -25,11 +25,12 @@ import {
25
25
  resolveKnowledgeCounterBaselinePath,
26
26
  resolveKnowledgeEventsPath,
27
27
  resolveLegacyApplicationLogPath
28
- } from "./index-3yh67t1h.js";
29
- import"./index-qgeeyy75.js";
28
+ } from "./index-dc3j6jmk.js";
29
+ import"./index-4f4zv8pb.js";
30
30
  import"./index-zgwm4ryv.js";
31
- import"./index-bbsaxnj5.js";
31
+ import"./index-0pfqcjp6.js";
32
32
  import"./index-42cx6g2h.js";
33
+ import"./index-fsrp8wp3.js";
33
34
  import"./index-q2rrv0cy.js";
34
35
  import"./index-vvk2g744.js";
35
36
  import"./index-qe3v54nb.js";
@@ -34,13 +34,13 @@ import {
34
34
  transactFile,
35
35
  transactKnowledge,
36
36
  wordBigrams
37
- } from "./index-k5ey429j.js";
37
+ } from "./index-aws8yhwq.js";
38
38
  import"./index-bfwt3abw.js";
39
- import"./index-qgeeyy75.js";
40
- import"./index-jtqkh8jf.js";
39
+ import"./index-4f4zv8pb.js";
41
40
  import"./index-zgwm4ryv.js";
42
- import"./index-bbsaxnj5.js";
41
+ import"./index-0pfqcjp6.js";
43
42
  import"./index-42cx6g2h.js";
43
+ import"./index-fsrp8wp3.js";
44
44
  import"./index-q2rrv0cy.js";
45
45
  import"./index-vvk2g744.js";
46
46
  import"./index-qe3v54nb.js";
@@ -23,14 +23,14 @@ import {
23
23
  validateLesson,
24
24
  validateSkillCandidatePath,
25
25
  validateSkillPath
26
- } from "./index-jyetmzcn.js";
27
- import"./index-k5ey429j.js";
26
+ } from "./index-c9m5skgs.js";
27
+ import"./index-aws8yhwq.js";
28
28
  import"./index-bfwt3abw.js";
29
- import"./index-qgeeyy75.js";
30
- import"./index-jtqkh8jf.js";
29
+ import"./index-4f4zv8pb.js";
31
30
  import"./index-zgwm4ryv.js";
32
- import"./index-bbsaxnj5.js";
31
+ import"./index-0pfqcjp6.js";
33
32
  import"./index-42cx6g2h.js";
33
+ import"./index-fsrp8wp3.js";
34
34
  import"./index-q2rrv0cy.js";
35
35
  import"./index-vvk2g744.js";
36
36
  import"./index-qe3v54nb.js";
@@ -1,8 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  validateSwarmPath
4
- } from "./index-wh8949ef.js";
5
- import"./index-jtqkh8jf.js";
4
+ } from "./index-kzj3fp7c.js";
6
5
  import"./index-5e4e2hvv.js";
7
6
  import"./index-p0arc26j.js";
8
7
  import {
@@ -15,6 +14,7 @@ import {
15
14
  import {
16
15
  withEvidenceLock
17
16
  } from "./index-42cx6g2h.js";
17
+ import"./index-fsrp8wp3.js";
18
18
  import"./index-q2rrv0cy.js";
19
19
  import"./index-vvk2g744.js";
20
20
  import"./index-qe3v54nb.js";
@@ -9,14 +9,14 @@ import {
9
9
  sweepStale,
10
10
  unsubscribe,
11
11
  updateSnapshot
12
- } from "./index-a6f8b0vn.js";
13
- import"./index-wh8949ef.js";
14
- import"./index-jtqkh8jf.js";
12
+ } from "./index-5bcrp3bc.js";
13
+ import"./index-kzj3fp7c.js";
15
14
  import"./index-5e4e2hvv.js";
16
15
  import"./index-p0arc26j.js";
17
16
  import"./index-zgwm4ryv.js";
18
17
  import"./index-293f68mj.js";
19
18
  import"./index-42cx6g2h.js";
19
+ import"./index-fsrp8wp3.js";
20
20
  import"./index-q2rrv0cy.js";
21
21
  import"./index-vvk2g744.js";
22
22
  import"./index-qe3v54nb.js";
@@ -33,16 +33,16 @@ import {
33
33
  sanitizeSlug,
34
34
  selectCandidateEntries,
35
35
  writeEvalStub
36
- } from "./index-s385axt1.js";
37
- import"./index-jyetmzcn.js";
38
- import"./index-3yh67t1h.js";
39
- import"./index-k5ey429j.js";
36
+ } from "./index-hskmya46.js";
37
+ import"./index-c9m5skgs.js";
38
+ import"./index-dc3j6jmk.js";
39
+ import"./index-aws8yhwq.js";
40
40
  import"./index-bfwt3abw.js";
41
- import"./index-qgeeyy75.js";
42
- import"./index-jtqkh8jf.js";
41
+ import"./index-4f4zv8pb.js";
43
42
  import"./index-zgwm4ryv.js";
44
- import"./index-bbsaxnj5.js";
43
+ import"./index-0pfqcjp6.js";
45
44
  import"./index-42cx6g2h.js";
45
+ import"./index-fsrp8wp3.js";
46
46
  import"./index-q2rrv0cy.js";
47
47
  import"./index-vvk2g744.js";
48
48
  import"./index-qe3v54nb.js";
@@ -156,6 +156,17 @@ export declare function runCleanStage(ctx: CloseStageContext): Promise<CleanStag
156
156
  * the close summary. All warnings are pushed into ctx.warnings.
157
157
  */
158
158
  export declare function runAlignStage(ctx: CloseStageContext): Promise<GitAlignResult>;
159
+ /**
160
+ * Builds the `/swarm finalize --dry-run` report. Purely READ-ONLY: inspects the
161
+ * plan and the filesystem and describes what a real finalize WOULD do, without
162
+ * acquiring the finalize lock, creating an archive bundle, deleting any file,
163
+ * running git, or tearing down session state. (#1692)
164
+ *
165
+ * The archive-first guard means the clean stage only removes files it first
166
+ * archived successfully; this report approximates that by listing existing
167
+ * clean-set members as "would remove" and notes the approximation.
168
+ */
169
+ export declare function runFinalizeDryRun(directory: string, swarmDir: string, planData: PlanData, planExists: boolean): Promise<string>;
159
170
  /**
160
171
  * Handles /swarm close command - performs full terminal session finalization:
161
172
  * 0. Guarantee: mark all incomplete phases/tasks as closed
@@ -198,6 +209,7 @@ export declare const _internals: {
198
209
  runArchiveEvidenceRetention: typeof runArchiveEvidenceRetention;
199
210
  runCleanStage: typeof runCleanStage;
200
211
  runAlignStage: typeof runAlignStage;
212
+ runFinalizeDryRun: typeof runFinalizeDryRun;
201
213
  archiveEvidence: typeof archiveEvidence;
202
214
  closePlanTerminalState: typeof closePlanTerminalState;
203
215
  endAgentSession: typeof endAgentSession;
@@ -7,13 +7,16 @@
7
7
  * keeping an isolated `.swarm/knowledge.jsonl`.
8
8
  *
9
9
  * Usage:
10
- * - /swarm link — link using the project hash (ties all worktrees
11
- * of the same repo to one shared store).
10
+ * - /swarm link — link using the canonical cohort id (ties all
11
+ * worktrees of the same repo to one shared store).
12
12
  * - /swarm link <name> — link using an explicit shared name (use the same
13
13
  * name in each worktree/repo to tie them together).
14
14
  * - /swarm link status — show the current link state for this worktree.
15
15
  *
16
- * On link, this worktree's existing local lessons are merged (deduplicated) into
17
- * the shared store so nothing already learned is lost.
16
+ * On link, this worktree's existing local knowledge *family* (store, events,
17
+ * rejected, retractions, counters, quarantine, unactionable, application-legacy)
18
+ * is migrated into the shared store per the family manifest, with each member
19
+ * merged according to its strategy (issue #1846). The pointer is flipped only
20
+ * after the migration commits.
18
21
  */
19
22
  export declare function handleLinkCommand(directory: string, args: string[]): Promise<string>;
@@ -381,16 +381,16 @@ export declare const COMMAND_REGISTRY: {
381
381
  readonly finalize: {
382
382
  readonly handler: (ctx: CommandContext) => Promise<string>;
383
383
  readonly description: "Use /swarm finalize to finalize the swarm project and archive evidence";
384
- readonly details: "Idempotent 4-stage terminal finalization: (1) finalize writes retrospectives for in-progress phases, (2) archive creates timestamped bundle of swarm artifacts and evidence, (3) clean removes active-state files for a clean slate, (4) align performs aggressive git reset --hard to the default remote branch, discarding uncommitted changes and gitignored build artifacts (user-created untracked files are preserved); falls back to a cautious reset that preserves uncommitted changes when the aggressive path cannot proceed. WARNING: alignment discards local changes and gitignored files. Resets agent sessions and delegation chains. Reads .swarm/close-lessons.md for explicit lessons and runs curation. Use --skill-review to run the quota-bounded skill_improver in proposal mode.";
385
- readonly args: "--prune-branches, --skill-review";
384
+ readonly details: "Idempotent 4-stage terminal finalization: (1) finalize writes retrospectives for in-progress phases, (2) archive creates timestamped bundle of swarm artifacts and evidence, (3) clean removes active-state files for a clean slate, (4) align performs aggressive git reset --hard to the default remote branch, discarding uncommitted changes and gitignored build artifacts (user-created untracked files are preserved); falls back to a cautious reset that preserves uncommitted changes when the aggressive path cannot proceed. WARNING: alignment discards local changes and gitignored files. Resets agent sessions and delegation chains. Reads .swarm/close-lessons.md for explicit lessons and runs curation. Use --skill-review to run the quota-bounded skill_improver in proposal mode. Use --dry-run to preview what finalize would archive, clean, and align without taking the lock or changing anything.";
385
+ readonly args: "--prune-branches, --skill-review, --dry-run";
386
386
  readonly category: "core";
387
387
  readonly toolPolicy: "none";
388
388
  };
389
389
  readonly close: {
390
390
  readonly handler: (ctx: CommandContext) => Promise<string>;
391
391
  readonly description: "Use /swarm close (deprecated alias) to finalize and archive swarm state";
392
- readonly details: "Deprecated alias for /swarm finalize. Preserved for backward compatibility.";
393
- readonly args: "--prune-branches, --skill-review";
392
+ readonly details: "Deprecated alias for /swarm finalize. Preserved for backward compatibility. Supports the same flags, including --dry-run.";
393
+ readonly args: "--prune-branches, --skill-review, --dry-run";
394
394
  readonly category: "core";
395
395
  readonly aliasOf: "finalize";
396
396
  readonly deprecated: true;
@@ -698,7 +698,7 @@ export declare const COMMAND_REGISTRY: {
698
698
  readonly reset: {
699
699
  readonly handler: (ctx: CommandContext) => Promise<string>;
700
700
  readonly description: "Clear swarm state files [--confirm]";
701
- readonly details: "DELETES plan.md, context.md, and summaries/ directory from .swarm/. Stops background automation and clears in-memory queues. SAFETY: requires --confirm flag — without it, displays a warning and tips to export first.";
701
+ readonly details: "DELETES plan.md, context.md, and summaries/ directory from .swarm/. Stops background automation and clears in-memory queues. SAFETY: requires --confirm flag — without it, displays a warning and tips to export first. Before deleting, auto-backs up the state it removes to .swarm/reset-backups/<timestamp>/ (newest 5 kept) so it can be restored by copying the files back.";
702
702
  readonly args: "--confirm (required)";
703
703
  readonly category: "utility";
704
704
  readonly clashesWithNativeCcCommand: "/reset";
@@ -707,7 +707,7 @@ export declare const COMMAND_REGISTRY: {
707
707
  readonly 'reset-session': {
708
708
  readonly handler: (ctx: CommandContext) => Promise<string>;
709
709
  readonly description: "Clear session state while preserving plan, evidence, and knowledge";
710
- readonly details: "Deletes only .swarm/session/state.json and any other session files. Clears in-memory agent sessions and delegation chains. Preserves plan, evidence, and knowledge for cross-session continuity.";
710
+ readonly details: "Deletes only .swarm/session/state.json and any other session files. Clears in-memory agent sessions and delegation chains. Preserves plan, evidence, and knowledge for cross-session continuity. Before deleting, auto-backs up the session files it removes to .swarm/reset-backups/<timestamp>/ (newest 5 kept).";
711
711
  readonly args: "";
712
712
  readonly category: "utility";
713
713
  readonly toolPolicy: "restricted";
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Result of an auto-backup taken before a destructive /swarm reset or
3
+ * /swarm reset-session. Fail-open by contract: any per-entry failure is
4
+ * recorded as a warning and never thrown.
5
+ */
6
+ export interface ResetBackupResult {
7
+ /** Absolute path of the backup directory, or null if nothing was backed up. */
8
+ backupDir: string | null;
9
+ /** Relative names actually copied into the backup. */
10
+ copied: string[];
11
+ /** Non-fatal warnings (source unreadable, prune failure, etc.). */
12
+ warnings: string[];
13
+ }
14
+ /** How many backup directories to retain under .swarm/reset-backups/. */
15
+ export declare const RESET_BACKUP_RETENTION = 5;
16
+ /**
17
+ * Copy the swarm-state entries a reset is about to delete into a durable,
18
+ * timestamped directory under `.swarm/reset-backups/` BEFORE deletion, so the
19
+ * user can recover by copying the files back. The backup directory is not part
20
+ * of any reset deletion set, so it survives the reset.
21
+ *
22
+ * This deliberately does NOT use the git checkpoint tool: that tool excludes
23
+ * `.swarm/` (`git add ... :!.swarm/`) — i.e. it excludes exactly the state a
24
+ * reset destroys — and would commit unrelated working-tree changes to the
25
+ * user's branch. A direct file copy of the deleted state is the faithful,
26
+ * non-surprising backup. (#1692)
27
+ *
28
+ * @param directory project root (contains `.swarm/`)
29
+ * @param kind backup label prefix ('reset' | 'reset-session')
30
+ * @param relEntries entries relative to `.swarm/` to back up (files or dirs)
31
+ */
32
+ export declare function backupSwarmStateBeforeReset(directory: string, kind: 'reset' | 'reset-session', relEntries: string[]): ResetBackupResult;
@@ -1,4 +1,5 @@
1
1
  import { type OrphanCleanupResult } from '../worktree/merge';
2
+ import { type ResetBackupResult } from './reset-backup';
2
3
  /**
3
4
  * _internals DI seam for testing reset-session without spawning real git processes.
4
5
  * Production code calls `_internals.cleanupOrphanedBranches(...)` so tests can
@@ -7,6 +8,7 @@ import { type OrphanCleanupResult } from '../worktree/merge';
7
8
  */
8
9
  export declare const _internals: {
9
10
  cleanupOrphanedBranches: (directory: string, activeSessionIds: string[]) => Promise<OrphanCleanupResult>;
11
+ backupSwarmStateBeforeReset: (directory: string, kind: 'reset' | 'reset-session', relEntries: string[]) => ResetBackupResult;
10
12
  };
11
13
  /**
12
14
  * Handles the /swarm reset-session command.
@@ -1,3 +1,12 @@
1
+ import { type ResetBackupResult } from './reset-backup';
2
+ /**
3
+ * _internals DI seam so tests can stub the pre-deletion backup without touching
4
+ * the real filesystem-copy helper. Mutations are file-scoped and restorable in
5
+ * afterEach.
6
+ */
7
+ export declare const _internals: {
8
+ backupSwarmStateBeforeReset: (directory: string, kind: 'reset' | 'reset-session', relEntries: string[]) => ResetBackupResult;
9
+ };
1
10
  /**
2
11
  * Handles the /swarm reset command.
3
12
  * Clears all swarm state files from .swarm/ and project root.
@@ -2,12 +2,19 @@
2
2
  * Handles the `/swarm unlink` command.
3
3
  *
4
4
  * Stops sharing this worktree's swarm knowledge with its link store and returns
5
- * it to a local `.swarm/knowledge.jsonl`. By default the shared lessons are
6
- * copied back into the local store (deduplicated) so the worktree keeps the
7
- * pooled knowledge it had access to; pass `--no-copy` to skip the copy-back.
5
+ * it to a local `.swarm/knowledge.jsonl`. By default the shared knowledge
6
+ * *family* (store, events, rejected, retractions, counters, quarantine,
7
+ * unactionable, application-legacy) is copied back into the local store per the
8
+ * family manifest so the worktree keeps the pooled knowledge it had access to;
9
+ * pass `--no-copy` to skip the copy-back.
10
+ *
11
+ * The copy-back is transactional (issue #1846): it reads the shared family
12
+ * under the shared-store lock and writes the local family atomically, so a
13
+ * concurrent append in a peer worktree cannot be lost. The shared cohort is
14
+ * never deleted or truncated.
8
15
  *
9
16
  * Usage:
10
- * - /swarm unlink — unlink and copy shared lessons back to local.
11
- * - /swarm unlink --no-copy — unlink without copying shared lessons back.
17
+ * - /swarm unlink — unlink and copy the shared family back to local.
18
+ * - /swarm unlink --no-copy — unlink without copying the shared family back.
12
19
  */
13
20
  export declare function handleUnlinkCommand(directory: string, args: string[]): Promise<string>;
@@ -39,6 +39,13 @@ export declare const _internals: {
39
39
  * Atomic write: write to a unique temp file, then rename over the target.
40
40
  * The rename is atomic on POSIX and Windows, so readers never observe a torn
41
41
  * file. The temp file is cleaned up in `finally` (no-op once renamed away).
42
+ *
43
+ * Invalidates any swarm-artifact-cache entry for `targetPath` after a
44
+ * successful rename: the cache's stat-based staleness check can collide on a
45
+ * same-size rewrite that lands within one filesystem timestamp tick (issue
46
+ * #1729), which would otherwise let a read immediately following this write
47
+ * (e.g. a second locked transaction in the same logical operation) observe
48
+ * the pre-write content instead of what was just committed.
42
49
  */
43
50
  export declare function atomicWriteFile(targetPath: string, content: string): Promise<void>;
44
51
  /**
@@ -267,6 +267,7 @@ export interface CounterRollup {
267
267
  }
268
268
  /** Cap on retained per-entry violation timestamps. */
269
269
  export declare const MAX_VIOLATION_TIMESTAMPS = 10;
270
+ declare function mergeRollupInto(target: CounterRollup, source: CounterRollup): void;
270
271
  declare function readCounterBaseline(directory: string): Promise<Map<string, CounterRollup>>;
271
272
  /**
272
273
  * Recompute per-entry counters deterministically from the immutable event log,
@@ -362,5 +363,6 @@ export declare const _internals: {
362
363
  appendHiveKnowledgeEvent: typeof appendHiveKnowledgeEvent;
363
364
  recordHiveKnowledgeEvent: typeof recordHiveKnowledgeEvent;
364
365
  readHiveKnowledgeEvents: typeof readHiveKnowledgeEvents;
366
+ mergeRollupInto: typeof mergeRollupInto;
365
367
  };
366
368
  export {};
@@ -27,7 +27,8 @@
27
27
  */
28
28
  /** On-disk pointer at `<directory>/.swarm/link.json`. */
29
29
  export interface LinkPointer {
30
- version: 1;
30
+ /** Pointer schema version. v1 pointers stay valid; v2 carries cohort metadata. */
31
+ version: 1 | 2;
31
32
  /** Path-safe identifier of the shared store (projectHash or sanitized name). */
32
33
  linkId: string;
33
34
  /** Human-friendly name when the link was created from an explicit name. */
@@ -36,6 +37,16 @@ export interface LinkPointer {
36
37
  createdAt: string;
37
38
  /** How the link was established. */
38
39
  source: 'manual' | 'auto';
40
+ /** Canonical cohort id from `resolveCohortId` (issue #1846). */
41
+ cohortId?: string;
42
+ /** How the cohort id was derived. */
43
+ identitySource?: 'remote' | 'git-common-dir' | 'path';
44
+ /** True when the cohort id is machine-local (git-common-dir/path fallback). */
45
+ degraded?: boolean;
46
+ /** Deterministic hash of cohort-relevant config (issue #1846 §4). */
47
+ configFingerprint?: string;
48
+ /** Monotonic generation counter, bumped on each link/unlink. Aids cache invalidation. */
49
+ generation?: number;
39
50
  }
40
51
  export interface LinkedLocalKnowledgeStatus {
41
52
  linked: boolean;
@@ -55,7 +66,13 @@ export declare function resolveLinkDir(linkId: string): string;
55
66
  * project hash). Lowercased for case-insensitive stability across worktrees.
56
67
  */
57
68
  export declare function sanitizeLinkId(name: string): string | null;
58
- /** Read and validate the link pointer for a worktree. Null if absent/invalid. */
69
+ /**
70
+ * Read and validate the link pointer for a worktree. Null if absent/invalid.
71
+ *
72
+ * Schema-version aware (issue #1846): reads `version` from disk rather than
73
+ * hard-stamping `1`, validates it is a known version, and preserves v2 cohort
74
+ * metadata fields when present. Unknown fields are ignored (forward-compat).
75
+ */
59
76
  export declare function readLinkPointer(directory: string): LinkPointer | null;
60
77
  export declare function getLinkedLocalKnowledgeStatus(directory: string): LinkedLocalKnowledgeStatus;
61
78
  /** Write the link pointer atomically and invalidate the resolution cache. */
@@ -67,8 +84,18 @@ export declare function removeLinkPointer(directory: string): Promise<void>;
67
84
  *
68
85
  * Returns the shared link directory when an active pointer is present, otherwise
69
86
  * the local `<directory>/.swarm`. Fail-open: any read/parse error degrades to the
70
- * local directory, so a corrupt pointer never strands knowledge. Synchronous and
71
- * cached so the hot retrieval path pays at most one tiny file read per TTL window.
87
+ * local directory, so a corrupt pointer never strands knowledge. Synchronous
88
+ * and cached; on a cache hit a cheap `stat` of the pointer file revalidates
89
+ * cross-process changes so the hot retrieval path stays fast while still
90
+ * observing link/unlink without waiting for the TTL to expire.
91
+ *
92
+ * Cross-process revalidation (issue #1846 §2): on a cache hit we additionally
93
+ * `stat` the pointer file and compare `mtimeMs:ctimeMs:size` to the cached
94
+ * fingerprint. A change (another process wrote/removed the pointer) invalidates
95
+ * the entry, so a stale process observes link/unlink without waiting for the
96
+ * TTL to expire. The TTL remains a backstop. The per-call `stat` is negligible
97
+ * (the pointer is tiny and almost never changes) and is the cost of correct
98
+ * cross-process link/unlink observation.
72
99
  *
73
100
  * NOTE: when unlinked, the return value is byte-identical to the legacy
74
101
  * `path.join(directory, '.swarm')`, so existing callers/tests are unaffected.