@webpieces/rules-config 0.4.836 → 0.4.838

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 (129) hide show
  1. package/package.json +4 -2
  2. package/src/builds-log.d.ts +1 -1
  3. package/src/builds-log.js +3 -3
  4. package/src/builds-log.js.map +1 -1
  5. package/src/checklist-docs-validator.js +1 -1
  6. package/src/checklist-docs-validator.js.map +1 -1
  7. package/src/checklist-override.js +1 -1
  8. package/src/checklist-override.js.map +1 -1
  9. package/src/config-file.js +3 -3
  10. package/src/config-file.js.map +1 -1
  11. package/src/config-pruner.d.ts +1 -1
  12. package/src/config-pruner.js +2 -2
  13. package/src/config-pruner.js.map +1 -1
  14. package/src/constants.d.ts +0 -2
  15. package/src/constants.js +1 -3
  16. package/src/constants.js.map +1 -1
  17. package/src/diff-scope.js +1 -1
  18. package/src/diff-scope.js.map +1 -1
  19. package/src/exclude-hook-paths.js +2 -2
  20. package/src/exclude-hook-paths.js.map +1 -1
  21. package/src/home-config-doc-keys.js +2 -2
  22. package/src/home-config-doc-keys.js.map +1 -1
  23. package/src/home-config.js +9 -9
  24. package/src/home-config.js.map +1 -1
  25. package/src/index.d.ts +2 -21
  26. package/src/index.js +7 -129
  27. package/src/index.js.map +1 -1
  28. package/src/instruct-ai-docs.d.ts +1 -1
  29. package/src/instruct-ai-docs.js +3 -3
  30. package/src/instruct-ai-docs.js.map +1 -1
  31. package/src/load-config.js +2 -2
  32. package/src/load-config.js.map +1 -1
  33. package/src/load-template.d.ts +2 -2
  34. package/src/load-template.js +5 -5
  35. package/src/load-template.js.map +1 -1
  36. package/src/orphan-dir-archive.js +3 -3
  37. package/src/orphan-dir-archive.js.map +1 -1
  38. package/src/pr-gate-config.js +4 -4
  39. package/src/pr-gate-config.js.map +1 -1
  40. package/src/pr-gate-section-validators.js +7 -7
  41. package/src/pr-gate-section-validators.js.map +1 -1
  42. package/src/repo-root.d.ts +1 -1
  43. package/src/repo-root.js +5 -5
  44. package/src/repo-root.js.map +1 -1
  45. package/src/repo-scratch-dirs.d.ts +1 -1
  46. package/src/repo-scratch-dirs.js +3 -3
  47. package/src/repo-scratch-dirs.js.map +1 -1
  48. package/src/review-json.d.ts +1 -1
  49. package/src/review-json.js +11 -11
  50. package/src/review-json.js.map +1 -1
  51. package/src/review-provenance.js +4 -4
  52. package/src/review-provenance.js.map +1 -1
  53. package/src/reviewer-instructions.js +2 -2
  54. package/src/reviewer-instructions.js.map +1 -1
  55. package/src/rules-config-design.d.ts +2 -2
  56. package/src/rules-config-design.js +4 -4
  57. package/src/rules-config-design.js.map +1 -1
  58. package/src/skip-rule.d.ts +2 -8
  59. package/src/skip-rule.js +24 -61
  60. package/src/skip-rule.js.map +1 -1
  61. package/src/spec-temp-dirs.js +2 -1
  62. package/src/spec-temp-dirs.js.map +1 -1
  63. package/src/stale-bin-sweep.js +1 -1
  64. package/src/stale-bin-sweep.js.map +1 -1
  65. package/src/subagent-provenance.js +7 -7
  66. package/src/subagent-provenance.js.map +1 -1
  67. package/src/tmp-scratch-sweep.js +1 -1
  68. package/src/tmp-scratch-sweep.js.map +1 -1
  69. package/src/validate-config.js +1 -1
  70. package/src/validate-config.js.map +1 -1
  71. package/src/verdict-schema-renderer.js +2 -2
  72. package/src/verdict-schema-renderer.js.map +1 -1
  73. package/src/agent-worktree-lock.d.ts +0 -21
  74. package/src/agent-worktree-lock.js +0 -77
  75. package/src/agent-worktree-lock.js.map +0 -1
  76. package/src/atomic-file.d.ts +0 -46
  77. package/src/atomic-file.js +0 -114
  78. package/src/atomic-file.js.map +0 -1
  79. package/src/branch-archiver.d.ts +0 -70
  80. package/src/branch-archiver.js +0 -157
  81. package/src/branch-archiver.js.map +0 -1
  82. package/src/branch-mutation-log.d.ts +0 -77
  83. package/src/branch-mutation-log.js +0 -221
  84. package/src/branch-mutation-log.js.map +0 -1
  85. package/src/branch-reaper.d.ts +0 -121
  86. package/src/branch-reaper.js +0 -260
  87. package/src/branch-reaper.js.map +0 -1
  88. package/src/claude-config-dir.d.ts +0 -62
  89. package/src/claude-config-dir.js +0 -87
  90. package/src/claude-config-dir.js.map +0 -1
  91. package/src/harness-agent-activity.d.ts +0 -154
  92. package/src/harness-agent-activity.js +0 -346
  93. package/src/harness-agent-activity.js.map +0 -1
  94. package/src/inform-ai-error.d.ts +0 -6
  95. package/src/inform-ai-error.js +0 -13
  96. package/src/inform-ai-error.js.map +0 -1
  97. package/src/main-sync-file.d.ts +0 -121
  98. package/src/main-sync-file.js +0 -281
  99. package/src/main-sync-file.js.map +0 -1
  100. package/src/main-sync-status.d.ts +0 -197
  101. package/src/main-sync-status.js +0 -555
  102. package/src/main-sync-status.js.map +0 -1
  103. package/src/merged-branch-verdicts.d.ts +0 -189
  104. package/src/merged-branch-verdicts.js +0 -251
  105. package/src/merged-branch-verdicts.js.map +0 -1
  106. package/src/merged-branches.d.ts +0 -140
  107. package/src/merged-branches.js +0 -521
  108. package/src/merged-branches.js.map +0 -1
  109. package/src/review-identity-stamp.d.ts +0 -82
  110. package/src/review-identity-stamp.js +0 -172
  111. package/src/review-identity-stamp.js.map +0 -1
  112. package/src/state-dir-migration.d.ts +0 -79
  113. package/src/state-dir-migration.js +0 -185
  114. package/src/state-dir-migration.js.map +0 -1
  115. package/src/state-dir.d.ts +0 -209
  116. package/src/state-dir.js +0 -349
  117. package/src/state-dir.js.map +0 -1
  118. package/src/to-error.d.ts +0 -1
  119. package/src/to-error.js +0 -10
  120. package/src/to-error.js.map +0 -1
  121. package/src/worktree-lock-verdicts.d.ts +0 -149
  122. package/src/worktree-lock-verdicts.js +0 -225
  123. package/src/worktree-lock-verdicts.js.map +0 -1
  124. package/src/worktree-reaper.d.ts +0 -116
  125. package/src/worktree-reaper.js +0 -318
  126. package/src/worktree-reaper.js.map +0 -1
  127. package/src/worktrees.d.ts +0 -113
  128. package/src/worktrees.js +0 -260
  129. package/src/worktrees.js.map +0 -1
@@ -1,114 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AtomicFile = void 0;
4
- const tslib_1 = require("tslib");
5
- const fs = tslib_1.__importStar(require("fs"));
6
- const path = tslib_1.__importStar(require("path"));
7
- const inversify_1 = require("inversify");
8
- const to_error_1 = require("./to-error");
9
- /**
10
- * Crash-safe / concurrency-safe file writes for the SHARED `.webpieces/` state dir.
11
- *
12
- * WHY this exists: once `.webpieces/` is shared by every linked worktree (see SharedStateDir), files
13
- * that used to have exactly ONE writer per worktree now have N concurrent writers across the repo —
14
- * seven agents, one `merged-branches.json`. A plain `fs.writeFileSync` TRUNCATES first and then writes,
15
- * so a reader that opens the file in that window reads a truncated or half-written document and its
16
- * `JSON.parse` throws. That is not theoretical: it is exactly the failure PR #526 had to paper over
17
- * from the READER side for webpieces.config.json (retry a transient parse failure). This fixes the
18
- * WRITER side, which is where it actually belongs — a reader retry cannot help a reader that is handed
19
- * a syntactically VALID prefix of a JSON document.
20
- *
21
- * The fix is write-to-temp-then-`rename()`. POSIX `rename(2)` within a single directory is atomic: a
22
- * concurrent reader sees either the entire old file or the entire new one, never a mix, and never a
23
- * zero-length file. The temp file MUST be created in the SAME directory as the destination, otherwise
24
- * the rename crosses a filesystem boundary, degrades to copy+unlink, and loses the atomicity.
25
- *
26
- * NOT everything should come through here. Append-only logs (`branch-mutations.log`,
27
- * `guard-*.log`) are already concurrency-safe by a different mechanism — `fs.appendFileSync` opens
28
- * with O_APPEND and issues ONE `write(2)` per record, which POSIX guarantees not to interleave for
29
- * writes under PIPE_BUF. Routing an append through a rename would be strictly WORSE: it would make
30
- * concurrent appenders clobber each other's lines wholesale.
31
- */
32
- let AtomicFile = class AtomicFile {
33
- // Distinguishes temp files written by the same process within the same millisecond. Combined with
34
- // the pid this makes the temp name unique across every concurrent writer of a shared file.
35
- sequence = 0;
36
- /**
37
- * Write `contents` to `absPath` so that no concurrent reader can ever observe a partial file.
38
- * Creates the parent directory. Throws only if the write itself genuinely failed (disk full,
39
- * permissions) — callers that must not fail wrap this.
40
- */
41
- writeAtomic(absPath, contents) {
42
- const dir = path.dirname(absPath);
43
- fs.mkdirSync(dir, { recursive: true });
44
- const tmpPath = this.tempPathFor(absPath);
45
- // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
46
- try {
47
- fs.writeFileSync(tmpPath, contents);
48
- fs.renameSync(tmpPath, absPath);
49
- }
50
- catch (err) {
51
- const error = (0, to_error_1.toError)(err);
52
- this.discard(tmpPath);
53
- throw new Error(`Failed atomic write of ${absPath}: ${error.message}`, { cause: error });
54
- }
55
- }
56
- /** `writeAtomic` of a pretty-printed JSON document, trailing newline included. */
57
- writeJsonAtomic(absPath, value) {
58
- this.writeAtomic(absPath, JSON.stringify(value, null, 2) + '\n');
59
- }
60
- /**
61
- * Atomic write, SKIPPED when the file already holds exactly `contents`. Returns true when it wrote.
62
- *
63
- * This is the instruct-ai regeneration case: every `wp-*` command rewrites the same generated docs,
64
- * and with a shared `.webpieces/` those rewrites now overlap across worktrees. Identical content is
65
- * the overwhelmingly common case, so the cheapest correct answer is to not write at all; when the
66
- * content genuinely changed, the write is atomic so a concurrent reader never sees a half-doc.
67
- */
68
- writeIfChanged(absPath, contents) {
69
- if (this.alreadyHolds(absPath, contents))
70
- return false;
71
- this.writeAtomic(absPath, contents);
72
- return true;
73
- }
74
- // True when the file exists and its bytes already equal `contents`. Any read failure answers false
75
- // (rewrite it) — "cannot read the current content" must never read as "it is already correct".
76
- alreadyHolds(absPath, contents) {
77
- // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
78
- try {
79
- if (!fs.existsSync(absPath))
80
- return false;
81
- return fs.readFileSync(absPath, 'utf8') === contents;
82
- }
83
- catch (err) {
84
- const error = (0, to_error_1.toError)(err);
85
- void error;
86
- return false;
87
- }
88
- }
89
- // A sibling of the destination (same directory ⇒ same filesystem ⇒ the rename stays atomic), named
90
- // so a crash leaves an obviously-temporary dotfile rather than something mistaken for real state.
91
- tempPathFor(absPath) {
92
- this.sequence += 1;
93
- const stamp = `${String(process.pid)}-${String(Date.now())}-${String(this.sequence)}`;
94
- return path.join(path.dirname(absPath), `.${path.basename(absPath)}.tmp-${stamp}`);
95
- }
96
- // Best-effort removal of an abandoned temp file. A failure here is not worth reporting over the
97
- // original write failure that caused it.
98
- discard(tmpPath) {
99
- // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
100
- try {
101
- if (fs.existsSync(tmpPath))
102
- fs.unlinkSync(tmpPath);
103
- }
104
- catch (err) {
105
- const error = (0, to_error_1.toError)(err);
106
- void error;
107
- }
108
- }
109
- };
110
- exports.AtomicFile = AtomicFile;
111
- exports.AtomicFile = AtomicFile = tslib_1.__decorate([
112
- (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton)
113
- ], AtomicFile);
114
- //# sourceMappingURL=atomic-file.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"atomic-file.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/atomic-file.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,mDAA6B;AAC7B,yCAA2D;AAE3D,yCAAqC;AAErC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEI,IAAM,UAAU,GAAhB,MAAM,UAAU;IACnB,kGAAkG;IAClG,2FAA2F;IACnF,QAAQ,GAAW,CAAC,CAAC;IAE7B;;;;OAIG;IACH,WAAW,CAAC,OAAe,EAAE,QAAgB;QACzC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAClC,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACvC,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAC1C,8DAA8D;QAC9D,IAAI,CAAC;YACD,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YACpC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACpC,CAAC;QAAC,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CAAC;QACnB,MAAM,KAAK,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QACtF,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,KAAK,EAAE,CAAC,CAAC;IACvF,CAAC;IAED,gGAAgG;IAChG,yCAAyC;IACjC,OAAO,CAAC,OAAe;QAC3B,8DAA8D;QAC9D,IAAI,CAAC;YACD,IAAI,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC;gBAAE,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QACvD,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;YAC3B,KAAK,KAAK,CAAC;QACf,CAAC;IACL,CAAC;CACJ,CAAA;AA7EY,gCAAU;qBAAV,UAAU;IADtB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,UAAU,CA6EtB","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { toError } from './to-error';\n\n/**\n * Crash-safe / concurrency-safe file writes for the SHARED `.webpieces/` state dir.\n *\n * WHY this exists: once `.webpieces/` is shared by every linked worktree (see SharedStateDir), files\n * that used to have exactly ONE writer per worktree now have N concurrent writers across the repo —\n * seven agents, one `merged-branches.json`. A plain `fs.writeFileSync` TRUNCATES first and then writes,\n * so a reader that opens the file in that window reads a truncated or half-written document and its\n * `JSON.parse` throws. That is not theoretical: it is exactly the failure PR #526 had to paper over\n * from the READER side for webpieces.config.json (retry a transient parse failure). This fixes the\n * WRITER side, which is where it actually belongs — a reader retry cannot help a reader that is handed\n * a syntactically VALID prefix of a JSON document.\n *\n * The fix is write-to-temp-then-`rename()`. POSIX `rename(2)` within a single directory is atomic: a\n * concurrent reader sees either the entire old file or the entire new one, never a mix, and never a\n * zero-length file. The temp file MUST be created in the SAME directory as the destination, otherwise\n * the rename crosses a filesystem boundary, degrades to copy+unlink, and loses the atomicity.\n *\n * NOT everything should come through here. Append-only logs (`branch-mutations.log`,\n * `guard-*.log`) are already concurrency-safe by a different mechanism — `fs.appendFileSync` opens\n * with O_APPEND and issues ONE `write(2)` per record, which POSIX guarantees not to interleave for\n * writes under PIPE_BUF. Routing an append through a rename would be strictly WORSE: it would make\n * concurrent appenders clobber each other's lines wholesale.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class AtomicFile {\n // Distinguishes temp files written by the same process within the same millisecond. Combined with\n // the pid this makes the temp name unique across every concurrent writer of a shared file.\n private sequence: number = 0;\n\n /**\n * Write `contents` to `absPath` so that no concurrent reader can ever observe a partial file.\n * Creates the parent directory. Throws only if the write itself genuinely failed (disk full,\n * permissions) — callers that must not fail wrap this.\n */\n writeAtomic(absPath: string, contents: string): void {\n const dir = path.dirname(absPath);\n fs.mkdirSync(dir, { recursive: true });\n const tmpPath = this.tempPathFor(absPath);\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n fs.writeFileSync(tmpPath, contents);\n fs.renameSync(tmpPath, absPath);\n } catch (err: unknown) {\n const error = toError(err);\n this.discard(tmpPath);\n throw new Error(`Failed atomic write of ${absPath}: ${error.message}`, { cause: error });\n }\n }\n\n /** `writeAtomic` of a pretty-printed JSON document, trailing newline included. */\n writeJsonAtomic(absPath: string, value: object): void {\n this.writeAtomic(absPath, JSON.stringify(value, null, 2) + '\\n');\n }\n\n /**\n * Atomic write, SKIPPED when the file already holds exactly `contents`. Returns true when it wrote.\n *\n * This is the instruct-ai regeneration case: every `wp-*` command rewrites the same generated docs,\n * and with a shared `.webpieces/` those rewrites now overlap across worktrees. Identical content is\n * the overwhelmingly common case, so the cheapest correct answer is to not write at all; when the\n * content genuinely changed, the write is atomic so a concurrent reader never sees a half-doc.\n */\n writeIfChanged(absPath: string, contents: string): boolean {\n if (this.alreadyHolds(absPath, contents)) return false;\n this.writeAtomic(absPath, contents);\n return true;\n }\n\n // True when the file exists and its bytes already equal `contents`. Any read failure answers false\n // (rewrite it) — \"cannot read the current content\" must never read as \"it is already correct\".\n private alreadyHolds(absPath: string, contents: string): boolean {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n if (!fs.existsSync(absPath)) return false;\n return fs.readFileSync(absPath, 'utf8') === contents;\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return false;\n }\n }\n\n // A sibling of the destination (same directory ⇒ same filesystem ⇒ the rename stays atomic), named\n // so a crash leaves an obviously-temporary dotfile rather than something mistaken for real state.\n private tempPathFor(absPath: string): string {\n this.sequence += 1;\n const stamp = `${String(process.pid)}-${String(Date.now())}-${String(this.sequence)}`;\n return path.join(path.dirname(absPath), `.${path.basename(absPath)}.tmp-${stamp}`);\n }\n\n // Best-effort removal of an abandoned temp file. A failure here is not worth reporting over the\n // original write failure that caused it.\n private discard(tmpPath: string): void {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n if (fs.existsSync(tmpPath)) fs.unlinkSync(tmpPath);\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n }\n }\n}\n"]}
@@ -1,70 +0,0 @@
1
- /**
2
- * Archive a branch tip as a git TAG immediately before the branch is deleted.
3
- *
4
- * WHY this exists: `<feature>PreMerge<n>` snapshot BRANCHES exist for a real reason — after a squash
5
- * merge you sometimes need the original pre-merge history to debug — but they are branches, so they
6
- * accumulate forever, count toward `branch-creation-guard`'s maxLocalBranches, and can be committed
7
- * onto by accident. Observed in the wild: 6 parked branches against a cap of 5, which then REFUSED to
8
- * create the escape branch and pushed the agent into editing webpieces.config.json to get out.
9
- *
10
- * A tag is strictly better at the one job the branch was doing:
11
- * - vs KEEPING THE BRANCH — a tag is invisible to `git branch`, does not count toward the branch cap,
12
- * and cannot be accidentally committed onto.
13
- * - vs storing a PATCH in merge-info — a patch is lossy: it drops commit boundaries, messages,
14
- * authorship and parentage. A tag preserves the exact objects.
15
- * - vs relying on the REFLOG — the reflog expires (90 days by default) and is local to the one clone
16
- * that did the work. A tag survives `gc` and can be pushed if durability beyond one machine is wanted.
17
- *
18
- * Cost: one ref, zero new objects — the commits are already in the object store.
19
- *
20
- * Round trip (verified by hand, and asserted in branch-archiver.spec.ts against a real repo):
21
- * git tag archive/2026-07-30/dean/foo dean/foo
22
- * git branch -D dean/foo
23
- * git checkout -b dean/foo archive/2026-07-30/dean/foo # exact objects restored
24
- */
25
- export declare const BRANCH_RETENTION_DELETE = "delete";
26
- export declare const BRANCH_RETENTION_ARCHIVE_TAG = "archive-tag";
27
- export declare const BRANCH_RETENTION_KEEP = "keep";
28
- export declare const BRANCH_RETENTIONS: readonly string[];
29
- export declare const ARCHIVE_TAG_PREFIX = "archive";
30
- export declare class ArchiveResult {
31
- tag: string;
32
- sha: string;
33
- ok: boolean;
34
- error: string;
35
- constructor(tag: string, sha: string, ok: boolean, error: string);
36
- }
37
- export declare class BranchArchiver {
38
- /**
39
- * `archive/<YYYY-MM-DD>/<branch>`. The date segment is what makes the namespace browsable
40
- * chronologically (`git tag --list 'archive/2026-07-*'`) and is also what keeps two archives of the
41
- * SAME branch name from colliding across days — the common case, since a branch name gets reused.
42
- */
43
- archiveTagName(branch: string, when?: Date): string;
44
- /**
45
- * Tag `branch`'s current tip, never overwriting an existing tag.
46
- *
47
- * Same branch archived twice on the SAME day gets `…-2`, `…-3`, … rather than `git tag -f`: force
48
- * would silently destroy the older archive, which is the exact failure the archive exists to prevent.
49
- * Returns ok=false (with git's stderr) rather than throwing — an archive that cannot be written must
50
- * turn into "then do not delete either", a decision the CALLER makes.
51
- *
52
- * IDEMPOTENT for the same tip: if the base name is already taken by a tag pointing at the SAME sha,
53
- * that tag is returned as-is rather than minting a `-2` beside it. Re-archiving an identical tip is
54
- * not a collision — it is the same archive — and `wp-land-pr` produces exactly that case, tagging
55
- * the branch in its own recap and then handing the worktree reap to a child that (correctly,
56
- * because it trusts nothing the parent told it) archives again a second later. Without this the
57
- * archive namespace fills with `…` / `…-2` pairs at one sha, which reads like two distinct
58
- * snapshots and is one more ref to explain.
59
- */
60
- archive(repoRoot: string, branch: string, when?: Date): ArchiveResult;
61
- /** The literal command a human runs to bring an archived branch back, byte-identical to what was deleted. */
62
- restoreCommand(branch: string, tag: string): string;
63
- /** Every archive tag currently in the repo, newest namespace segment first (plain lexical on the date). */
64
- listArchiveTags(repoRoot: string): string[];
65
- private freeTagName;
66
- private tagSha;
67
- protected tagExists(repoRoot: string, tag: string): boolean;
68
- private dateSegment;
69
- private capture;
70
- }
@@ -1,157 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BranchArchiver = exports.ArchiveResult = exports.ARCHIVE_TAG_PREFIX = exports.BRANCH_RETENTIONS = exports.BRANCH_RETENTION_KEEP = exports.BRANCH_RETENTION_ARCHIVE_TAG = exports.BRANCH_RETENTION_DELETE = void 0;
4
- const tslib_1 = require("tslib");
5
- const child_process_1 = require("child_process");
6
- const inversify_1 = require("inversify");
7
- /**
8
- * Archive a branch tip as a git TAG immediately before the branch is deleted.
9
- *
10
- * WHY this exists: `<feature>PreMerge<n>` snapshot BRANCHES exist for a real reason — after a squash
11
- * merge you sometimes need the original pre-merge history to debug — but they are branches, so they
12
- * accumulate forever, count toward `branch-creation-guard`'s maxLocalBranches, and can be committed
13
- * onto by accident. Observed in the wild: 6 parked branches against a cap of 5, which then REFUSED to
14
- * create the escape branch and pushed the agent into editing webpieces.config.json to get out.
15
- *
16
- * A tag is strictly better at the one job the branch was doing:
17
- * - vs KEEPING THE BRANCH — a tag is invisible to `git branch`, does not count toward the branch cap,
18
- * and cannot be accidentally committed onto.
19
- * - vs storing a PATCH in merge-info — a patch is lossy: it drops commit boundaries, messages,
20
- * authorship and parentage. A tag preserves the exact objects.
21
- * - vs relying on the REFLOG — the reflog expires (90 days by default) and is local to the one clone
22
- * that did the work. A tag survives `gc` and can be pushed if durability beyond one machine is wanted.
23
- *
24
- * Cost: one ref, zero new objects — the commits are already in the object store.
25
- *
26
- * Round trip (verified by hand, and asserted in branch-archiver.spec.ts against a real repo):
27
- * git tag archive/2026-07-30/dean/foo dean/foo
28
- * git branch -D dean/foo
29
- * git checkout -b dean/foo archive/2026-07-30/dean/foo # exact objects restored
30
- */
31
- // Retention policy for a branch whose PR has landed (or which wp-cleanup proved dead).
32
- // DELETE — delete outright, recoverable only via the reflog (the pre-0.4.492 behaviour).
33
- // ARCHIVE_TAG — tag the tip first, then delete. The default: same disk cost, permanently recoverable.
34
- // KEEP — do not delete at all (the branch keeps counting toward the branch cap).
35
- exports.BRANCH_RETENTION_DELETE = 'delete';
36
- exports.BRANCH_RETENTION_ARCHIVE_TAG = 'archive-tag';
37
- exports.BRANCH_RETENTION_KEEP = 'keep';
38
- exports.BRANCH_RETENTIONS = [
39
- exports.BRANCH_RETENTION_DELETE,
40
- exports.BRANCH_RETENTION_ARCHIVE_TAG,
41
- exports.BRANCH_RETENTION_KEEP,
42
- ];
43
- // The one namespace every archive tag lives under, so `git tag --list 'archive/*'` is the whole
44
- // inventory and `git push origin 'refs/tags/archive/*'` is the whole backup.
45
- exports.ARCHIVE_TAG_PREFIX = 'archive';
46
- // Data-only (per CLAUDE.md, classes for data): what archiving one branch produced.
47
- // `tag` is '' when nothing was tagged — either the policy said not to, or git refused; `error` says which.
48
- class ArchiveResult {
49
- tag;
50
- sha;
51
- ok;
52
- error;
53
- constructor(tag, sha, ok, error) {
54
- this.tag = tag;
55
- this.sha = sha;
56
- this.ok = ok;
57
- this.error = error;
58
- }
59
- }
60
- exports.ArchiveResult = ArchiveResult;
61
- let BranchArchiver = class BranchArchiver {
62
- /**
63
- * `archive/<YYYY-MM-DD>/<branch>`. The date segment is what makes the namespace browsable
64
- * chronologically (`git tag --list 'archive/2026-07-*'`) and is also what keeps two archives of the
65
- * SAME branch name from colliding across days — the common case, since a branch name gets reused.
66
- */
67
- archiveTagName(branch, when = new Date()) {
68
- return `${exports.ARCHIVE_TAG_PREFIX}/${this.dateSegment(when)}/${branch}`;
69
- }
70
- /**
71
- * Tag `branch`'s current tip, never overwriting an existing tag.
72
- *
73
- * Same branch archived twice on the SAME day gets `…-2`, `…-3`, … rather than `git tag -f`: force
74
- * would silently destroy the older archive, which is the exact failure the archive exists to prevent.
75
- * Returns ok=false (with git's stderr) rather than throwing — an archive that cannot be written must
76
- * turn into "then do not delete either", a decision the CALLER makes.
77
- *
78
- * IDEMPOTENT for the same tip: if the base name is already taken by a tag pointing at the SAME sha,
79
- * that tag is returned as-is rather than minting a `-2` beside it. Re-archiving an identical tip is
80
- * not a collision — it is the same archive — and `wp-land-pr` produces exactly that case, tagging
81
- * the branch in its own recap and then handing the worktree reap to a child that (correctly,
82
- * because it trusts nothing the parent told it) archives again a second later. Without this the
83
- * archive namespace fills with `…` / `…-2` pairs at one sha, which reads like two distinct
84
- * snapshots and is one more ref to explain.
85
- */
86
- archive(repoRoot, branch, when = new Date()) {
87
- const resolved = this.capture(repoRoot, ['rev-parse', branch]);
88
- if (!resolved.ok)
89
- return new ArchiveResult('', '', false, `cannot resolve ${branch}: ${resolved.err}`);
90
- const sha = resolved.out;
91
- const base = this.archiveTagName(branch, when);
92
- if (this.tagExists(repoRoot, base) && this.tagSha(repoRoot, base) === sha) {
93
- return new ArchiveResult(base, sha, true, '');
94
- }
95
- const tag = this.freeTagName(repoRoot, base);
96
- const tagged = this.capture(repoRoot, ['tag', tag, sha]);
97
- if (!tagged.ok)
98
- return new ArchiveResult('', sha, false, tagged.err);
99
- return new ArchiveResult(tag, sha, true, '');
100
- }
101
- /** The literal command a human runs to bring an archived branch back, byte-identical to what was deleted. */
102
- restoreCommand(branch, tag) {
103
- return `git checkout -b ${branch} ${tag}`;
104
- }
105
- /** Every archive tag currently in the repo, newest namespace segment first (plain lexical on the date). */
106
- listArchiveTags(repoRoot) {
107
- const result = this.capture(repoRoot, ['tag', '--list', `${exports.ARCHIVE_TAG_PREFIX}/*`]);
108
- if (!result.ok || result.out === '')
109
- return [];
110
- return result.out
111
- .split('\n')
112
- .map((line) => line.trim())
113
- .filter((line) => line !== '')
114
- .sort()
115
- .reverse();
116
- }
117
- // First unused name in the `<base>`, `<base>-2`, `<base>-3` … series. Bounded so a pathological repo
118
- // cannot spin: past the bound we hand back the last candidate and let `git tag` report the collision.
119
- freeTagName(repoRoot, base) {
120
- const MAX_ATTEMPTS = 50;
121
- let candidate = base;
122
- for (let attempt = 2; attempt <= MAX_ATTEMPTS; attempt += 1) {
123
- if (!this.tagExists(repoRoot, candidate))
124
- return candidate;
125
- candidate = `${base}-${String(attempt)}`;
126
- }
127
- return candidate;
128
- }
129
- // The COMMIT an existing tag points at, '' when it cannot be resolved. `^{commit}` peels an
130
- // annotated tag, so an archive written by hand with `git tag -a` compares equal to a lightweight one.
131
- tagSha(repoRoot, tag) {
132
- const result = this.capture(repoRoot, ['rev-parse', `refs/tags/${tag}^{commit}`]);
133
- return result.ok ? result.out : '';
134
- }
135
- // Seam: overridden in the spec so name-collision logic is testable with no git and no repo.
136
- tagExists(repoRoot, tag) {
137
- return this.capture(repoRoot, ['rev-parse', '--verify', '--quiet', `refs/tags/${tag}`]).ok;
138
- }
139
- // YYYY-MM-DD in LOCAL time: the archive is browsed by the human who created it, on their calendar.
140
- dateSegment(when) {
141
- const pad = (value) => String(value).padStart(2, '0');
142
- return `${String(when.getFullYear())}-${pad(when.getMonth() + 1)}-${pad(when.getDate())}`;
143
- }
144
- capture(repoRoot, args) {
145
- const result = (0, child_process_1.spawnSync)('git', args, { cwd: repoRoot, encoding: 'utf8' });
146
- const err = typeof result.stderr === 'string' ? result.stderr.trim() : '';
147
- if (result.status !== 0 || typeof result.stdout !== 'string') {
148
- return { ok: false, out: '', err: err !== '' ? err : 'git command failed' };
149
- }
150
- return { ok: true, out: result.stdout.trim(), err };
151
- }
152
- };
153
- exports.BranchArchiver = BranchArchiver;
154
- exports.BranchArchiver = BranchArchiver = tslib_1.__decorate([
155
- (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton)
156
- ], BranchArchiver);
157
- //# sourceMappingURL=branch-archiver.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"branch-archiver.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/branch-archiver.ts"],"names":[],"mappings":";;;;AAAA,iDAA0C;AAC1C,yCAA2D;AAE3D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,uFAAuF;AACvF,8FAA8F;AAC9F,sGAAsG;AACtG,wFAAwF;AAC3E,QAAA,uBAAuB,GAAG,QAAQ,CAAC;AACnC,QAAA,4BAA4B,GAAG,aAAa,CAAC;AAC7C,QAAA,qBAAqB,GAAG,MAAM,CAAC;AAC/B,QAAA,iBAAiB,GAAsB;IAChD,+BAAuB;IACvB,oCAA4B;IAC5B,6BAAqB;CACxB,CAAC;AAEF,gGAAgG;AAChG,6EAA6E;AAChE,QAAA,kBAAkB,GAAG,SAAS,CAAC;AAE5C,mFAAmF;AACnF,2GAA2G;AAC3G,MAAa,aAAa;IACtB,GAAG,CAAS;IACZ,GAAG,CAAS;IACZ,EAAE,CAAU;IACZ,KAAK,CAAS;IAEd,YAAY,GAAW,EAAE,GAAW,EAAE,EAAW,EAAE,KAAa;QAC5D,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;CACJ;AAZD,sCAYC;AAUM,IAAM,cAAc,GAApB,MAAM,cAAc;IACvB;;;;OAIG;IACH,cAAc,CAAC,MAAc,EAAE,OAAa,IAAI,IAAI,EAAE;QAClD,OAAO,GAAG,0BAAkB,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC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AAC,CAAC,oBAAoB,EAAE,CAAC;QAChF,CAAC;QACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,CAAC;IACxD,CAAC;CACJ,CAAA;AAjGY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,cAAc,CAiG1B","sourcesContent":["import { spawnSync } from 'child_process';\nimport { injectable, bindingScopeValues } from 'inversify';\n\n/**\n * Archive a branch tip as a git TAG immediately before the branch is deleted.\n *\n * WHY this exists: `<feature>PreMerge<n>` snapshot BRANCHES exist for a real reason — after a squash\n * merge you sometimes need the original pre-merge history to debug — but they are branches, so they\n * accumulate forever, count toward `branch-creation-guard`'s maxLocalBranches, and can be committed\n * onto by accident. Observed in the wild: 6 parked branches against a cap of 5, which then REFUSED to\n * create the escape branch and pushed the agent into editing webpieces.config.json to get out.\n *\n * A tag is strictly better at the one job the branch was doing:\n * - vs KEEPING THE BRANCH — a tag is invisible to `git branch`, does not count toward the branch cap,\n * and cannot be accidentally committed onto.\n * - vs storing a PATCH in merge-info — a patch is lossy: it drops commit boundaries, messages,\n * authorship and parentage. A tag preserves the exact objects.\n * - vs relying on the REFLOG — the reflog expires (90 days by default) and is local to the one clone\n * that did the work. A tag survives `gc` and can be pushed if durability beyond one machine is wanted.\n *\n * Cost: one ref, zero new objects — the commits are already in the object store.\n *\n * Round trip (verified by hand, and asserted in branch-archiver.spec.ts against a real repo):\n * git tag archive/2026-07-30/dean/foo dean/foo\n * git branch -D dean/foo\n * git checkout -b dean/foo archive/2026-07-30/dean/foo # exact objects restored\n */\n\n// Retention policy for a branch whose PR has landed (or which wp-cleanup proved dead).\n// DELETE — delete outright, recoverable only via the reflog (the pre-0.4.492 behaviour).\n// ARCHIVE_TAG — tag the tip first, then delete. The default: same disk cost, permanently recoverable.\n// KEEP — do not delete at all (the branch keeps counting toward the branch cap).\nexport const BRANCH_RETENTION_DELETE = 'delete';\nexport const BRANCH_RETENTION_ARCHIVE_TAG = 'archive-tag';\nexport const BRANCH_RETENTION_KEEP = 'keep';\nexport const BRANCH_RETENTIONS: readonly string[] = [\n BRANCH_RETENTION_DELETE,\n BRANCH_RETENTION_ARCHIVE_TAG,\n BRANCH_RETENTION_KEEP,\n];\n\n// The one namespace every archive tag lives under, so `git tag --list 'archive/*'` is the whole\n// inventory and `git push origin 'refs/tags/archive/*'` is the whole backup.\nexport const ARCHIVE_TAG_PREFIX = 'archive';\n\n// Data-only (per CLAUDE.md, classes for data): what archiving one branch produced.\n// `tag` is '' when nothing was tagged — either the policy said not to, or git refused; `error` says which.\nexport class ArchiveResult {\n tag: string;\n sha: string;\n ok: boolean;\n error: string;\n\n constructor(tag: string, sha: string, ok: boolean, error: string) {\n this.tag = tag;\n this.sha = sha;\n this.ok = ok;\n this.error = error;\n }\n}\n\n// Result of a captured git invocation. `err` carries stderr so a refused tag can be reported verbatim.\ninterface CmdCapture {\n ok: boolean;\n out: string;\n err: string;\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class BranchArchiver {\n /**\n * `archive/<YYYY-MM-DD>/<branch>`. The date segment is what makes the namespace browsable\n * chronologically (`git tag --list 'archive/2026-07-*'`) and is also what keeps two archives of the\n * SAME branch name from colliding across days — the common case, since a branch name gets reused.\n */\n archiveTagName(branch: string, when: Date = new Date()): string {\n return `${ARCHIVE_TAG_PREFIX}/${this.dateSegment(when)}/${branch}`;\n }\n\n /**\n * Tag `branch`'s current tip, never overwriting an existing tag.\n *\n * Same branch archived twice on the SAME day gets `…-2`, `…-3`, … rather than `git tag -f`: force\n * would silently destroy the older archive, which is the exact failure the archive exists to prevent.\n * Returns ok=false (with git's stderr) rather than throwing — an archive that cannot be written must\n * turn into \"then do not delete either\", a decision the CALLER makes.\n *\n * IDEMPOTENT for the same tip: if the base name is already taken by a tag pointing at the SAME sha,\n * that tag is returned as-is rather than minting a `-2` beside it. Re-archiving an identical tip is\n * not a collision — it is the same archive — and `wp-land-pr` produces exactly that case, tagging\n * the branch in its own recap and then handing the worktree reap to a child that (correctly,\n * because it trusts nothing the parent told it) archives again a second later. Without this the\n * archive namespace fills with `…` / `…-2` pairs at one sha, which reads like two distinct\n * snapshots and is one more ref to explain.\n */\n archive(repoRoot: string, branch: string, when: Date = new Date()): ArchiveResult {\n const resolved = this.capture(repoRoot, ['rev-parse', branch]);\n if (!resolved.ok) return new ArchiveResult('', '', false, `cannot resolve ${branch}: ${resolved.err}`);\n const sha = resolved.out;\n\n const base = this.archiveTagName(branch, when);\n if (this.tagExists(repoRoot, base) && this.tagSha(repoRoot, base) === sha) {\n return new ArchiveResult(base, sha, true, '');\n }\n\n const tag = this.freeTagName(repoRoot, base);\n const tagged = this.capture(repoRoot, ['tag', tag, sha]);\n if (!tagged.ok) return new ArchiveResult('', sha, false, tagged.err);\n return new ArchiveResult(tag, sha, true, '');\n }\n\n /** The literal command a human runs to bring an archived branch back, byte-identical to what was deleted. */\n restoreCommand(branch: string, tag: string): string {\n return `git checkout -b ${branch} ${tag}`;\n }\n\n /** Every archive tag currently in the repo, newest namespace segment first (plain lexical on the date). */\n listArchiveTags(repoRoot: string): string[] {\n const result = this.capture(repoRoot, ['tag', '--list', `${ARCHIVE_TAG_PREFIX}/*`]);\n if (!result.ok || result.out === '') return [];\n return result.out\n .split('\\n')\n .map((line: string): string => line.trim())\n .filter((line: string): boolean => line !== '')\n .sort()\n .reverse();\n }\n\n // First unused name in the `<base>`, `<base>-2`, `<base>-3` … series. Bounded so a pathological repo\n // cannot spin: past the bound we hand back the last candidate and let `git tag` report the collision.\n private freeTagName(repoRoot: string, base: string): string {\n const MAX_ATTEMPTS = 50;\n let candidate = base;\n for (let attempt = 2; attempt <= MAX_ATTEMPTS; attempt += 1) {\n if (!this.tagExists(repoRoot, candidate)) return candidate;\n candidate = `${base}-${String(attempt)}`;\n }\n return candidate;\n }\n\n // The COMMIT an existing tag points at, '' when it cannot be resolved. `^{commit}` peels an\n // annotated tag, so an archive written by hand with `git tag -a` compares equal to a lightweight one.\n private tagSha(repoRoot: string, tag: string): string {\n const result = this.capture(repoRoot, ['rev-parse', `refs/tags/${tag}^{commit}`]);\n return result.ok ? result.out : '';\n }\n\n // Seam: overridden in the spec so name-collision logic is testable with no git and no repo.\n protected tagExists(repoRoot: string, tag: string): boolean {\n return this.capture(repoRoot, ['rev-parse', '--verify', '--quiet', `refs/tags/${tag}`]).ok;\n }\n\n // YYYY-MM-DD in LOCAL time: the archive is browsed by the human who created it, on their calendar.\n private dateSegment(when: Date): string {\n const pad = (value: number): string => String(value).padStart(2, '0');\n return `${String(when.getFullYear())}-${pad(when.getMonth() + 1)}-${pad(when.getDate())}`;\n }\n\n private capture(repoRoot: string, args: string[]): CmdCapture {\n const result = spawnSync('git', args, { cwd: repoRoot, encoding: 'utf8' });\n const err = typeof result.stderr === 'string' ? result.stderr.trim() : '';\n if (result.status !== 0 || typeof result.stdout !== 'string') {\n return { ok: false, out: '', err: err !== '' ? err : 'git command failed' };\n }\n return { ok: true, out: result.stdout.trim(), err };\n }\n}\n"]}
@@ -1,77 +0,0 @@
1
- import { DotWebpieces } from './state-dir';
2
- export type MutationVerb = 'wp-start-update' | 'wp-finish-update' | 'wp-start-upsert-pr' | 'wp-review-upsert-pr' | 'wp-finish-upsert-pr' | 'wp-cleanup' | 'wp-land-pr' | 'auto-reap';
3
- export type MutationPhase = 'START' | 'BACKUP' | 'CHECKOUT_MAIN' | 'PULL' | 'SQUASH' | 'RENAME' | 'FINALIZE' | 'CONFLICT' | 'INTERRUPTED' | 'END' | 'REAP' | 'REAP_WORKTREE';
4
- export declare class BranchMutationEvent {
5
- verb: MutationVerb;
6
- phase: MutationPhase;
7
- fromBranch: string;
8
- toBranch: string;
9
- oldMain: string;
10
- newMain: string;
11
- conflict: boolean;
12
- conflictFiles: string[];
13
- outcome: string;
14
- artifacts: string[];
15
- sha: string;
16
- archiveTag: string;
17
- worktreePath: string;
18
- constructor(verb: MutationVerb, phase: MutationPhase);
19
- }
20
- /** Appends branch-mutation audit lines. `@injectable(bindingScopeValues.Singleton)` so it's injectable + drawn in the design. */
21
- export declare class BranchMutationLog {
22
- private readonly dotDir;
23
- constructor(dotDir?: DotWebpieces);
24
- /**
25
- * LOCAL scope, deliberately — one log per worktree, not one per repo.
26
- *
27
- * A SHARED append-only log would genuinely corrupt. `O_APPEND` makes a write indivisible only up to
28
- * PIPE_BUF, which is 512 bytes on macOS, and a REAP_WORKTREE line carrying
29
- * `recover=git worktree add -b <branch> <absolute-path> <tag>` exceeds that — concurrent appenders
30
- * from seven worktrees would interleave into an unrecoverable audit trail, which is the one thing
31
- * this file exists not to be. Per-worktree, THIS log has one writer and cannot tear.
32
- *
33
- * That last claim is narrower than it looks, so do not generalise it (2026-08-06). It holds here
34
- * because the wp-* bins write this file one command at a time. It does NOT hold for the ai-hook
35
- * logs in the same directory: Claude Code runs every matching PreToolUse hook IN PARALLEL, and
36
- * several agents and sessions can share one tree, so a per-worktree name there had several
37
- * concurrent writers. Those names now carry a `<sessionId>-<agentId|coordinator>-<hook>-` prefix
38
- * (ai-hook-rules' LogStream), and the rejection DETAIL files sit in a directory of that same name.
39
- *
40
- * This file keeps a bare name deliberately, for TWO independent reasons, and neither has gone away
41
- * (re-checked 2026-08-07). First, LogStream lives in ai-hook-rules, which DEPENDS on rules-config,
42
- * so the import direction forbids reusing it here. Second — and this is the one that would still
43
- * bite after moving the class down — the `wp-*` bins that write this file have NO session or agent
44
- * identity to prefix with: those ids reach a PreToolUse hook on its JSON payload and a plain Bash
45
- * tool call never sees them. Routing this through LogStream today would therefore produce
46
- * `unknown-coordinator-hook-branch-mutations.log`: one shared file, exactly as now, under a longer
47
- * name, plus a rename of a log people already grep. If this log ever gains a second concurrent
48
- * writer, it needs a real stream identity FIRST — the prefix is only worth having when it
49
- * discriminates.
50
- *
51
- * Nothing is lost by keeping it local: under the `worktrees/<name>/` layout the log lives in the
52
- * PRIMARY clone, so it survives `git worktree remove`, and the whole history is one glob —
53
- * `<primary>/.webpieces/worktrees/*/logs/branch-mutations.log`.
54
- */
55
- branchMutationLogPath(root: string): string;
56
- /**
57
- * Append one tab-separated line per branch-mutation event to
58
- * `.webpieces/logs/branch-mutations.log`. Swallows all errors — logging must NEVER block or fail
59
- * the workflow it is observing.
60
- */
61
- logBranchMutation(root: string, event: BranchMutationEvent): void;
62
- private formatDetail;
63
- /**
64
- * The worktree flavour of the sha/recover token: path, tip, archive tag and the ONE command that
65
- * puts the directory AND the branch back together.
66
- *
67
- * `git worktree add -b <branch> <path> <ref>` is verified by hand and in worktree-reaper.spec.ts —
68
- * plain `git worktree add <path> <tag>` would restore the files at a DETACHED HEAD, silently losing
69
- * the branch name the reap destroyed. Falls back to the sha when nothing was archived (retention
70
- * 'delete'), and to a bare `git worktree add <path>` when there was no branch at all (detached).
71
- */
72
- private worktreeDetail;
73
- private oneLine;
74
- private rotateLogFile;
75
- }
76
- export declare function branchMutationLogPath(root: string): string;
77
- export declare function logBranchMutation(root: string, event: BranchMutationEvent): void;