@webpieces/rules-config 0.4.837 → 0.4.839

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,82 +0,0 @@
1
- import { AtomicFile } from './atomic-file';
2
- import { DotWebpieces } from './state-dir';
3
- /** The ONE sanctioned way a reviewer submits a checklist verdict (issue #863). */
4
- export declare const WRITE_REVIEW_BIN = "wp-write-review";
5
- /** The flag that names the checklist a `wp-write-review` call submits for. */
6
- export declare const WRITE_REVIEW_CHECKLIST_FLAG = "--checklist";
7
- /** Where the stamps live, beneath this worktree's tooling-owned state dir (never the AI-writable one). */
8
- export declare const REVIEW_STAMP_DIR = "review-stamps";
9
- /**
10
- * How long a stamp stays usable. The hook writes it a few milliseconds before the harness starts the very
11
- * Bash command it stamped, so anything older than this is left over from a call that never reached the bin
12
- * — and must not be available to lend its identity to a later caller.
13
- */
14
- export declare const REVIEW_STAMP_MAX_AGE_MS = 120000;
15
- /**
16
- * WHO is running a `pnpm wp-write-review` Bash call, as the HARNESS reported it to the PreToolUse hook.
17
- * Data-only (per CLAUDE.md), and its field names are the JSON keys on disk.
18
- *
19
- * WHY a hook stamp and not the environment (issue #863). A Bash-invoked bin sees only its env, and the env
20
- * cannot answer "is this a subagent?" in either harness:
21
- * - Claude Code exports `CLAUDE_CODE_SESSION_ID`, which is the PARENT session's id in a subagent too, and
22
- * no agent id at all — a reviewer and its coordinator have byte-identical identity env.
23
- * - Codex exports `CODEX_SESSION_ID` / `CODEX_THREAD_ID`, and nothing documents (or has been measured to
24
- * show) that a spawned subagent gets a thread id of its own rather than inheriting the coordinator's.
25
- * The hook payload DOES carry the answer, in both harnesses, on the same key: `agent_id` is empty for the
26
- * main loop and populated for a subagent. So the hook — which sees every Bash call before it runs — writes
27
- * that identity here for each checklist the command names, and the bin consumes it.
28
- *
29
- * NOT tamper-proof, and not claimed to be: an agent can write this file by hand. It moves forging a verdict
30
- * from "write one JSON file" (what a coordinator did on two merged PRs) to a deliberate, auditable forgery of
31
- * tooling state outside the AI-writable dir — the same bar SubagentProvenanceService sets.
32
- */
33
- export declare class ReviewIdentityStamp {
34
- checklistId: string;
35
- aiType: string;
36
- sessionId: string;
37
- agentId: string;
38
- agentType: string;
39
- cwd: string;
40
- stampedAt: string;
41
- constructor(checklistId: string, aiType: string, sessionId: string, agentId: string, agentType: string, cwd: string, stampedAt: string);
42
- }
43
- /**
44
- * Writes (from the PreToolUse hook) and consumes (from `wp-write-review`) {@link ReviewIdentityStamp}s.
45
- *
46
- * Both ends resolve the path from their OWN working directory through {@link DotWebpieces.local}, which is
47
- * keyed by git's answer for that tree — so the hook's payload cwd and the bin's process cwd land on the same
48
- * file for the same worktree, and two worktrees never share a stamp.
49
- *
50
- * `@injectable(bindingScopeValues.Singleton)` so it is injected by type; {@link reviewIdentityStamps} is the
51
- * instance the dependency-free hook adapter uses.
52
- */
53
- export declare class ReviewIdentityStampService {
54
- private readonly dotDir;
55
- private readonly atomicFile;
56
- constructor(dotDir?: DotWebpieces, atomicFile?: AtomicFile);
57
- /**
58
- * The checklist ids a Bash command submits verdicts for, or [] when it does not invoke the bin at all.
59
- * Every `--checklist <id>` / `--checklist=<id>` is returned, because one reviewer covering several
60
- * checklists may chain several submissions into one command.
61
- */
62
- invokedChecklists(command: string): string[];
63
- /**
64
- * True when the stamp names the COORDINATING agent rather than a subagent: no agent id, or an agent id
65
- * equal to the session id (a harness that fills the main loop's agent id with the session id instead of
66
- * leaving it empty). The coordinator may never submit a reviewer's verdict — that is the whole point.
67
- */
68
- isCoordinator(stamp: ReviewIdentityStamp): boolean;
69
- stampPath(startDir: string, checklistId: string): string;
70
- /** Best-effort: a stamp that cannot be written makes the bin refuse, which is the safe direction. */
71
- write(startDir: string, stamp: ReviewIdentityStamp): void;
72
- /**
73
- * Read AND delete the stamp for one checklist. null when there is none, it is unreadable, or it is
74
- * older than {@link REVIEW_STAMP_MAX_AGE_MS}. Deleted on read so one hook call vouches for one
75
- * submission; a delete that fails (a sandbox that denies it) is harmless, because age bounds it anyway.
76
- */
77
- take(startDir: string, checklistId: string, nowMs?: number): ReviewIdentityStamp | null;
78
- private read;
79
- private remove;
80
- }
81
- /** The instance the hook adapter uses — it runs without a DI container (see hook-core.ts). */
82
- export declare const reviewIdentityStamps: ReviewIdentityStampService;
@@ -1,172 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.reviewIdentityStamps = exports.ReviewIdentityStampService = exports.ReviewIdentityStamp = exports.REVIEW_STAMP_MAX_AGE_MS = exports.REVIEW_STAMP_DIR = exports.WRITE_REVIEW_CHECKLIST_FLAG = exports.WRITE_REVIEW_BIN = void 0;
4
- const tslib_1 = require("tslib");
5
- const fs = tslib_1.__importStar(require("fs"));
6
- const inversify_1 = require("inversify");
7
- const atomic_file_1 = require("./atomic-file");
8
- const state_dir_1 = require("./state-dir");
9
- const to_error_1 = require("./to-error");
10
- /** The ONE sanctioned way a reviewer submits a checklist verdict (issue #863). */
11
- exports.WRITE_REVIEW_BIN = 'wp-write-review';
12
- /** The flag that names the checklist a `wp-write-review` call submits for. */
13
- exports.WRITE_REVIEW_CHECKLIST_FLAG = '--checklist';
14
- /** Where the stamps live, beneath this worktree's tooling-owned state dir (never the AI-writable one). */
15
- exports.REVIEW_STAMP_DIR = 'review-stamps';
16
- /**
17
- * How long a stamp stays usable. The hook writes it a few milliseconds before the harness starts the very
18
- * Bash command it stamped, so anything older than this is left over from a call that never reached the bin
19
- * — and must not be available to lend its identity to a later caller.
20
- */
21
- exports.REVIEW_STAMP_MAX_AGE_MS = 120_000;
22
- /**
23
- * WHO is running a `pnpm wp-write-review` Bash call, as the HARNESS reported it to the PreToolUse hook.
24
- * Data-only (per CLAUDE.md), and its field names are the JSON keys on disk.
25
- *
26
- * WHY a hook stamp and not the environment (issue #863). A Bash-invoked bin sees only its env, and the env
27
- * cannot answer "is this a subagent?" in either harness:
28
- * - Claude Code exports `CLAUDE_CODE_SESSION_ID`, which is the PARENT session's id in a subagent too, and
29
- * no agent id at all — a reviewer and its coordinator have byte-identical identity env.
30
- * - Codex exports `CODEX_SESSION_ID` / `CODEX_THREAD_ID`, and nothing documents (or has been measured to
31
- * show) that a spawned subagent gets a thread id of its own rather than inheriting the coordinator's.
32
- * The hook payload DOES carry the answer, in both harnesses, on the same key: `agent_id` is empty for the
33
- * main loop and populated for a subagent. So the hook — which sees every Bash call before it runs — writes
34
- * that identity here for each checklist the command names, and the bin consumes it.
35
- *
36
- * NOT tamper-proof, and not claimed to be: an agent can write this file by hand. It moves forging a verdict
37
- * from "write one JSON file" (what a coordinator did on two merged PRs) to a deliberate, auditable forgery of
38
- * tooling state outside the AI-writable dir — the same bar SubagentProvenanceService sets.
39
- */
40
- class ReviewIdentityStamp {
41
- checklistId;
42
- aiType; // 'claude-code' | 'codex' — the adapter's answer, never the model's
43
- sessionId;
44
- agentId; // '' ⇒ the MAIN loop, i.e. the coordinating agent
45
- agentType;
46
- cwd;
47
- stampedAt; // ISO
48
- // eslint-disable-next-line @typescript-eslint/max-params
49
- constructor(checklistId, aiType, sessionId, agentId, agentType, cwd, stampedAt) {
50
- this.checklistId = checklistId;
51
- this.aiType = aiType;
52
- this.sessionId = sessionId;
53
- this.agentId = agentId;
54
- this.agentType = agentType;
55
- this.cwd = cwd;
56
- this.stampedAt = stampedAt;
57
- }
58
- }
59
- exports.ReviewIdentityStamp = ReviewIdentityStamp;
60
- /**
61
- * Writes (from the PreToolUse hook) and consumes (from `wp-write-review`) {@link ReviewIdentityStamp}s.
62
- *
63
- * Both ends resolve the path from their OWN working directory through {@link DotWebpieces.local}, which is
64
- * keyed by git's answer for that tree — so the hook's payload cwd and the bin's process cwd land on the same
65
- * file for the same worktree, and two worktrees never share a stamp.
66
- *
67
- * `@injectable(bindingScopeValues.Singleton)` so it is injected by type; {@link reviewIdentityStamps} is the
68
- * instance the dependency-free hook adapter uses.
69
- */
70
- let ReviewIdentityStampService = class ReviewIdentityStampService {
71
- dotDir;
72
- atomicFile;
73
- constructor(dotDir = state_dir_1.dotWebpieces, atomicFile = new atomic_file_1.AtomicFile()) {
74
- this.dotDir = dotDir;
75
- this.atomicFile = atomicFile;
76
- }
77
- /**
78
- * The checklist ids a Bash command submits verdicts for, or [] when it does not invoke the bin at all.
79
- * Every `--checklist <id>` / `--checklist=<id>` is returned, because one reviewer covering several
80
- * checklists may chain several submissions into one command.
81
- */
82
- invokedChecklists(command) {
83
- if (!new RegExp(`\\b${exports.WRITE_REVIEW_BIN}\\b`).test(command))
84
- return [];
85
- const ids = [];
86
- const flag = /--checklist(?:=|\s+)(["']?)([A-Za-z0-9._-]+)\1/g;
87
- let match = flag.exec(command);
88
- while (match !== null) {
89
- if (!ids.includes(match[2]))
90
- ids.push(match[2]);
91
- match = flag.exec(command);
92
- }
93
- return ids;
94
- }
95
- /**
96
- * True when the stamp names the COORDINATING agent rather than a subagent: no agent id, or an agent id
97
- * equal to the session id (a harness that fills the main loop's agent id with the session id instead of
98
- * leaving it empty). The coordinator may never submit a reviewer's verdict — that is the whole point.
99
- */
100
- isCoordinator(stamp) {
101
- return stamp.agentId.trim() === '' || stamp.agentId === stamp.sessionId;
102
- }
103
- stampPath(startDir, checklistId) {
104
- return this.dotDir.localFile(startDir, exports.REVIEW_STAMP_DIR, `${checklistId.replace(/[^A-Za-z0-9._-]/g, '_')}.json`);
105
- }
106
- /** Best-effort: a stamp that cannot be written makes the bin refuse, which is the safe direction. */
107
- write(startDir, stamp) {
108
- // webpieces-disable no-unmanaged-exceptions -- chokepoint: the hook must never fail a tool call over its own bookkeeping
109
- // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
110
- try {
111
- this.atomicFile.writeJsonAtomic(this.stampPath(startDir, stamp.checklistId), stamp);
112
- }
113
- catch (err) {
114
- const error = (0, to_error_1.toError)(err);
115
- void error;
116
- }
117
- }
118
- /**
119
- * Read AND delete the stamp for one checklist. null when there is none, it is unreadable, or it is
120
- * older than {@link REVIEW_STAMP_MAX_AGE_MS}. Deleted on read so one hook call vouches for one
121
- * submission; a delete that fails (a sandbox that denies it) is harmless, because age bounds it anyway.
122
- */
123
- take(startDir, checklistId, nowMs = Date.now()) {
124
- const file = this.stampPath(startDir, checklistId);
125
- const stamp = this.read(file);
126
- this.remove(file);
127
- if (stamp === null || stamp.checklistId !== checklistId)
128
- return null;
129
- const age = nowMs - Date.parse(stamp.stampedAt);
130
- if (!Number.isFinite(age) || age < 0 || age > exports.REVIEW_STAMP_MAX_AGE_MS)
131
- return null;
132
- return stamp;
133
- }
134
- read(file) {
135
- if (!fs.existsSync(file))
136
- return null;
137
- // webpieces-disable no-unmanaged-exceptions -- chokepoint: an unreadable stamp is no stamp
138
- // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
139
- try {
140
- // webpieces-disable no-any-unknown -- opaque parsed JSON, narrowed field-by-field below
141
- const raw = JSON.parse(fs.readFileSync(file, 'utf8'));
142
- // webpieces-disable no-any-unknown -- one opaque JSON value, narrowed to a string
143
- const str = (v) => (typeof v === 'string' ? v : '');
144
- return new ReviewIdentityStamp(str(raw['checklistId']), str(raw['aiType']), str(raw['sessionId']), str(raw['agentId']), str(raw['agentType']), str(raw['cwd']), str(raw['stampedAt']));
145
- }
146
- catch (err) {
147
- const error = (0, to_error_1.toError)(err);
148
- void error;
149
- return null;
150
- }
151
- }
152
- remove(file) {
153
- // webpieces-disable no-unmanaged-exceptions -- chokepoint: a stamp that cannot be deleted still expires
154
- // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
155
- try {
156
- fs.rmSync(file, { force: true });
157
- }
158
- catch (err) {
159
- const error = (0, to_error_1.toError)(err);
160
- void error;
161
- }
162
- }
163
- };
164
- exports.ReviewIdentityStampService = ReviewIdentityStampService;
165
- exports.ReviewIdentityStampService = ReviewIdentityStampService = tslib_1.__decorate([
166
- (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
167
- tslib_1.__metadata("design:paramtypes", [state_dir_1.DotWebpieces,
168
- atomic_file_1.AtomicFile])
169
- ], ReviewIdentityStampService);
170
- /** The instance the hook adapter uses — it runs without a DI container (see hook-core.ts). */
171
- exports.reviewIdentityStamps = new ReviewIdentityStampService();
172
- //# sourceMappingURL=review-identity-stamp.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"review-identity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AG,CAAC,aAAa,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EACvF,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;QACvE,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;YAC3B,KAAK,KAAK,CAAC;YACX,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;IAEO,MAAM,CAAC,IAAY;QACvB,wGAAwG;QACxG,8DAA8D;QAC9D,IAAI,CAAC;YACD,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACrC,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;AA5FY,gEAA0B;qCAA1B,0BAA0B;IADtC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGR,wBAAY;QACR,wBAAU;GAHlC,0BAA0B,CA4FtC;AAED,8FAA8F;AACjF,QAAA,oBAAoB,GAAG,IAAI,0BAA0B,EAAE,CAAC","sourcesContent":["import * as fs from 'fs';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AtomicFile } from './atomic-file';\nimport { DotWebpieces, dotWebpieces } from './state-dir';\nimport { toError } from './to-error';\n\n/** The ONE sanctioned way a reviewer submits a checklist verdict (issue #863). */\nexport const WRITE_REVIEW_BIN = 'wp-write-review';\n\n/** The flag that names the checklist a `wp-write-review` call submits for. */\nexport const WRITE_REVIEW_CHECKLIST_FLAG = '--checklist';\n\n/** Where the stamps live, beneath this worktree's tooling-owned state dir (never the AI-writable one). */\nexport const REVIEW_STAMP_DIR = 'review-stamps';\n\n/**\n * How long a stamp stays usable. The hook writes it a few milliseconds before the harness starts the very\n * Bash command it stamped, so anything older than this is left over from a call that never reached the bin\n * — and must not be available to lend its identity to a later caller.\n */\nexport const REVIEW_STAMP_MAX_AGE_MS = 120_000;\n\n/**\n * WHO is running a `pnpm wp-write-review` Bash call, as the HARNESS reported it to the PreToolUse hook.\n * Data-only (per CLAUDE.md), and its field names are the JSON keys on disk.\n *\n * WHY a hook stamp and not the environment (issue #863). A Bash-invoked bin sees only its env, and the env\n * cannot answer \"is this a subagent?\" in either harness:\n * - Claude Code exports `CLAUDE_CODE_SESSION_ID`, which is the PARENT session's id in a subagent too, and\n * no agent id at all — a reviewer and its coordinator have byte-identical identity env.\n * - Codex exports `CODEX_SESSION_ID` / `CODEX_THREAD_ID`, and nothing documents (or has been measured to\n * show) that a spawned subagent gets a thread id of its own rather than inheriting the coordinator's.\n * The hook payload DOES carry the answer, in both harnesses, on the same key: `agent_id` is empty for the\n * main loop and populated for a subagent. So the hook — which sees every Bash call before it runs — writes\n * that identity here for each checklist the command names, and the bin consumes it.\n *\n * NOT tamper-proof, and not claimed to be: an agent can write this file by hand. It moves forging a verdict\n * from \"write one JSON file\" (what a coordinator did on two merged PRs) to a deliberate, auditable forgery of\n * tooling state outside the AI-writable dir — the same bar SubagentProvenanceService sets.\n */\nexport class ReviewIdentityStamp {\n checklistId: string;\n aiType: string; // 'claude-code' | 'codex' — the adapter's answer, never the model's\n sessionId: string;\n agentId: string; // '' ⇒ the MAIN loop, i.e. the coordinating agent\n agentType: string;\n cwd: string;\n stampedAt: string; // ISO\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(checklistId: string, aiType: string, sessionId: string, agentId: string, agentType: string, cwd: string, stampedAt: string) {\n this.checklistId = checklistId;\n this.aiType = aiType;\n this.sessionId = sessionId;\n this.agentId = agentId;\n this.agentType = agentType;\n this.cwd = cwd;\n this.stampedAt = stampedAt;\n }\n}\n\n/**\n * Writes (from the PreToolUse hook) and consumes (from `wp-write-review`) {@link ReviewIdentityStamp}s.\n *\n * Both ends resolve the path from their OWN working directory through {@link DotWebpieces.local}, which is\n * keyed by git's answer for that tree — so the hook's payload cwd and the bin's process cwd land on the same\n * file for the same worktree, and two worktrees never share a stamp.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is injected by type; {@link reviewIdentityStamps} is the\n * instance the dependency-free hook adapter uses.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ReviewIdentityStampService {\n constructor(\n private readonly dotDir: DotWebpieces = dotWebpieces,\n private readonly atomicFile: AtomicFile = new AtomicFile(),\n ) {}\n\n /**\n * The checklist ids a Bash command submits verdicts for, or [] when it does not invoke the bin at all.\n * Every `--checklist <id>` / `--checklist=<id>` is returned, because one reviewer covering several\n * checklists may chain several submissions into one command.\n */\n invokedChecklists(command: string): string[] {\n if (!new RegExp(`\\\\b${WRITE_REVIEW_BIN}\\\\b`).test(command)) return [];\n const ids: string[] = [];\n const flag = /--checklist(?:=|\\s+)([\"']?)([A-Za-z0-9._-]+)\\1/g;\n let match = flag.exec(command);\n while (match !== null) {\n if (!ids.includes(match[2])) ids.push(match[2]);\n match = flag.exec(command);\n }\n return ids;\n }\n\n /**\n * True when the stamp names the COORDINATING agent rather than a subagent: no agent id, or an agent id\n * equal to the session id (a harness that fills the main loop's agent id with the session id instead of\n * leaving it empty). The coordinator may never submit a reviewer's verdict — that is the whole point.\n */\n isCoordinator(stamp: ReviewIdentityStamp): boolean {\n return stamp.agentId.trim() === '' || stamp.agentId === stamp.sessionId;\n }\n\n stampPath(startDir: string, checklistId: string): string {\n return this.dotDir.localFile(startDir, REVIEW_STAMP_DIR, `${checklistId.replace(/[^A-Za-z0-9._-]/g, '_')}.json`);\n }\n\n /** Best-effort: a stamp that cannot be written makes the bin refuse, which is the safe direction. */\n write(startDir: string, stamp: ReviewIdentityStamp): void {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: the hook must never fail a tool call over its own bookkeeping\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n this.atomicFile.writeJsonAtomic(this.stampPath(startDir, stamp.checklistId), stamp);\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n }\n }\n\n /**\n * Read AND delete the stamp for one checklist. null when there is none, it is unreadable, or it is\n * older than {@link REVIEW_STAMP_MAX_AGE_MS}. Deleted on read so one hook call vouches for one\n * submission; a delete that fails (a sandbox that denies it) is harmless, because age bounds it anyway.\n */\n take(startDir: string, checklistId: string, nowMs: number = Date.now()): ReviewIdentityStamp | null {\n const file = this.stampPath(startDir, checklistId);\n const stamp = this.read(file);\n this.remove(file);\n if (stamp === null || stamp.checklistId !== checklistId) return null;\n const age = nowMs - Date.parse(stamp.stampedAt);\n if (!Number.isFinite(age) || age < 0 || age > REVIEW_STAMP_MAX_AGE_MS) return null;\n return stamp;\n }\n\n private read(file: string): ReviewIdentityStamp | null {\n if (!fs.existsSync(file)) return null;\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: an unreadable stamp is no stamp\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- opaque parsed JSON, narrowed field-by-field below\n const raw = JSON.parse(fs.readFileSync(file, 'utf8')) as Record<string, unknown>;\n // webpieces-disable no-any-unknown -- one opaque JSON value, narrowed to a string\n const str = (v: unknown): string => (typeof v === 'string' ? v : '');\n return new ReviewIdentityStamp(\n str(raw['checklistId']), str(raw['aiType']), str(raw['sessionId']), str(raw['agentId']),\n str(raw['agentType']), str(raw['cwd']), str(raw['stampedAt']));\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return null;\n }\n }\n\n private remove(file: string): void {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: a stamp that cannot be deleted still expires\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n fs.rmSync(file, { force: true });\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n }\n }\n}\n\n/** The instance the hook adapter uses — it runs without a DI container (see hook-core.ts). */\nexport const reviewIdentityStamps = new ReviewIdentityStampService();\n"]}
@@ -1,79 +0,0 @@
1
- /**
2
- * What a migration did. Data-only (per CLAUDE.md: classes for data, explicit construction).
3
- *
4
- * `kept` is the important half: an entry that could NOT be moved because the destination already holds
5
- * something at that path. Nothing in `kept` is ever deleted — it stays where it is, for a human.
6
- */
7
- export declare class StateMigrationReport {
8
- moved: string[];
9
- kept: string[];
10
- get movedAnything(): boolean;
11
- }
12
- /**
13
- * Moves a LEGACY per-worktree `.webpieces/` REAL DIRECTORY into the worktree's namespace inside the
14
- * primary clone (`<primary>/.webpieces/worktrees/<name>/`).
15
- *
16
- * NO SYMLINK IS EVER CREATED in its place — an earlier draft of this design planned one and this
17
- * comment still said so, which is worse than silence: it told the reader to expect an indirection
18
- * that does not exist. `DotWebpieces` resolves the namespace path EXPLICITLY (see its "Why two
19
- * explicit methods and not a symlink" section, which records why the link was rejected: lazy creation
20
- * with three failure modes, a Windows hazard, and `rename(2)` silently REPLACING the link). After a
21
- * migration the legacy `<worktree>/.webpieces/` is simply gone; nothing takes its place.
22
- *
23
- * WHY it must exist: those directories hold REAL in-flight state — above all a half-finished 3-point
24
- * merge under `merge-info/staged/<branch>/`. The first invocation under the new scheme must not orphan
25
- * them; a merge an agent is standing in the middle of is not recoverable by re-running anything.
26
- *
27
- * WHAT IT MUST NOT TOUCH: the `keepInPlace` leaves — `pr-review/` today. Those are not legacy at all;
28
- * `DotWebpieces.aiWritable()` resolves them to the worktree root ON PURPOSE, because that is the only
29
- * directory a worktree-isolated coding agent is permitted to write into. Draining one would delete the
30
- * live review directory out from under the agent writing it.
31
- *
32
- * WHY a plain move suffices: the destination namespace is created FOR this worktree, so it is empty in
33
- * the ordinary case and the whole tree moves in one `rename`. Where something is already there (a
34
- * repeat run, or an old PUBLISHED build having written to the legacy path again mid-transition), we
35
- * descend and move only what is free.
36
- *
37
- * SAFETY RULE, absolute: this never deletes or overwrites anything that holds content. If a
38
- * destination path is occupied, the legacy copy is LEFT WHERE IT IS and reported loudly on stderr.
39
- * Empty directories are removed as they drain, which is how a fully-migrated legacy `.webpieces/`
40
- * disappears on its own and lets the symlink be created.
41
- *
42
- * It is also the answer to the PUBLISHED-vs-LOCAL transition window. The `wp-*` bins and the hooks run
43
- * the PUBLISHED package, so for a while some invocations still create a REAL `<worktree>/.webpieces`
44
- * directory. Because this runs on the first state-dir resolution of EVERY new-code process, anything an
45
- * old-code invocation deposited is swept into the worktree namespace before any reader looks — and a
46
- * reader running old code finds it through the symlink either way. The two schemes converge instead of
47
- * splitting; nothing is lost in either direction.
48
- */
49
- export declare class StateDirMigrator {
50
- /**
51
- * Drain `legacyDir` into `targetDir`. A no-op when they are the same directory or when the legacy
52
- * dir does not exist / is not a real directory (a symlink means migration already happened).
53
- *
54
- * `keepInPlace` names the TOP-LEVEL leaves of `legacyDir` that are NOT legacy — the ones
55
- * `DotWebpieces.aiWritable()` deliberately resolves to the worktree's own root because a
56
- * worktree-isolated coding agent cannot write anywhere else (today: `pr-review/`). Sweeping those
57
- * into the namespace would move a live directory out from under the agent that is mid-way through
58
- * writing it, so they are skipped and NOT reported as kept — nothing about them is unresolved.
59
- */
60
- migrate(legacyDir: string, targetDir: string, keepInPlace: readonly string[]): StateMigrationReport;
61
- /**
62
- * Move everything under `<legacyRoot>/<relative>` to `<targetRoot>/<relative>`.
63
- *
64
- * A whole subtree whose destination is free moves in ONE `rename` — which is what keeps an
65
- * in-flight `merge-info/staged/<branch>/` intact rather than copying it file by file and risking a
66
- * half-moved merge. Only when the destination is an existing DIRECTORY do we descend and consider
67
- * its children individually.
68
- *
69
- * `keepInPlace` is consulted at the TOP LEVEL only (`relative === ''`), because that is the scope
70
- * `DotWebpieces.aiWritable()` assigns: a whole leaf of `.webpieces/` either lives in the worktree or
71
- * it does not. A nested `pr-review/` under some other home is ordinary legacy state.
72
- */
73
- private drain;
74
- private relocate;
75
- private isRealDirectory;
76
- private removeIfEmpty;
77
- private announce;
78
- private warn;
79
- }
@@ -1,185 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StateDirMigrator = exports.StateMigrationReport = 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
- * What a migration did. Data-only (per CLAUDE.md: classes for data, explicit construction).
11
- *
12
- * `kept` is the important half: an entry that could NOT be moved because the destination already holds
13
- * something at that path. Nothing in `kept` is ever deleted — it stays where it is, for a human.
14
- */
15
- class StateMigrationReport {
16
- moved = [];
17
- kept = [];
18
- get movedAnything() {
19
- return this.moved.length > 0;
20
- }
21
- }
22
- exports.StateMigrationReport = StateMigrationReport;
23
- /**
24
- * Moves a LEGACY per-worktree `.webpieces/` REAL DIRECTORY into the worktree's namespace inside the
25
- * primary clone (`<primary>/.webpieces/worktrees/<name>/`).
26
- *
27
- * NO SYMLINK IS EVER CREATED in its place — an earlier draft of this design planned one and this
28
- * comment still said so, which is worse than silence: it told the reader to expect an indirection
29
- * that does not exist. `DotWebpieces` resolves the namespace path EXPLICITLY (see its "Why two
30
- * explicit methods and not a symlink" section, which records why the link was rejected: lazy creation
31
- * with three failure modes, a Windows hazard, and `rename(2)` silently REPLACING the link). After a
32
- * migration the legacy `<worktree>/.webpieces/` is simply gone; nothing takes its place.
33
- *
34
- * WHY it must exist: those directories hold REAL in-flight state — above all a half-finished 3-point
35
- * merge under `merge-info/staged/<branch>/`. The first invocation under the new scheme must not orphan
36
- * them; a merge an agent is standing in the middle of is not recoverable by re-running anything.
37
- *
38
- * WHAT IT MUST NOT TOUCH: the `keepInPlace` leaves — `pr-review/` today. Those are not legacy at all;
39
- * `DotWebpieces.aiWritable()` resolves them to the worktree root ON PURPOSE, because that is the only
40
- * directory a worktree-isolated coding agent is permitted to write into. Draining one would delete the
41
- * live review directory out from under the agent writing it.
42
- *
43
- * WHY a plain move suffices: the destination namespace is created FOR this worktree, so it is empty in
44
- * the ordinary case and the whole tree moves in one `rename`. Where something is already there (a
45
- * repeat run, or an old PUBLISHED build having written to the legacy path again mid-transition), we
46
- * descend and move only what is free.
47
- *
48
- * SAFETY RULE, absolute: this never deletes or overwrites anything that holds content. If a
49
- * destination path is occupied, the legacy copy is LEFT WHERE IT IS and reported loudly on stderr.
50
- * Empty directories are removed as they drain, which is how a fully-migrated legacy `.webpieces/`
51
- * disappears on its own and lets the symlink be created.
52
- *
53
- * It is also the answer to the PUBLISHED-vs-LOCAL transition window. The `wp-*` bins and the hooks run
54
- * the PUBLISHED package, so for a while some invocations still create a REAL `<worktree>/.webpieces`
55
- * directory. Because this runs on the first state-dir resolution of EVERY new-code process, anything an
56
- * old-code invocation deposited is swept into the worktree namespace before any reader looks — and a
57
- * reader running old code finds it through the symlink either way. The two schemes converge instead of
58
- * splitting; nothing is lost in either direction.
59
- */
60
- let StateDirMigrator = class StateDirMigrator {
61
- /**
62
- * Drain `legacyDir` into `targetDir`. A no-op when they are the same directory or when the legacy
63
- * dir does not exist / is not a real directory (a symlink means migration already happened).
64
- *
65
- * `keepInPlace` names the TOP-LEVEL leaves of `legacyDir` that are NOT legacy — the ones
66
- * `DotWebpieces.aiWritable()` deliberately resolves to the worktree's own root because a
67
- * worktree-isolated coding agent cannot write anywhere else (today: `pr-review/`). Sweeping those
68
- * into the namespace would move a live directory out from under the agent that is mid-way through
69
- * writing it, so they are skipped and NOT reported as kept — nothing about them is unresolved.
70
- */
71
- migrate(legacyDir, targetDir, keepInPlace) {
72
- const report = new StateMigrationReport();
73
- if (path.resolve(legacyDir) === path.resolve(targetDir))
74
- return report;
75
- // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
76
- try {
77
- if (!this.isRealDirectory(legacyDir))
78
- return report;
79
- fs.mkdirSync(targetDir, { recursive: true });
80
- this.drain(legacyDir, targetDir, '', report, new Set(keepInPlace));
81
- this.removeIfEmpty(legacyDir);
82
- }
83
- catch (err) {
84
- const error = (0, to_error_1.toError)(err);
85
- this.warn(`could not migrate ${legacyDir} into ${targetDir}: ${error.message}`);
86
- return report;
87
- }
88
- this.announce(legacyDir, targetDir, report);
89
- return report;
90
- }
91
- /**
92
- * Move everything under `<legacyRoot>/<relative>` to `<targetRoot>/<relative>`.
93
- *
94
- * A whole subtree whose destination is free moves in ONE `rename` — which is what keeps an
95
- * in-flight `merge-info/staged/<branch>/` intact rather than copying it file by file and risking a
96
- * half-moved merge. Only when the destination is an existing DIRECTORY do we descend and consider
97
- * its children individually.
98
- *
99
- * `keepInPlace` is consulted at the TOP LEVEL only (`relative === ''`), because that is the scope
100
- * `DotWebpieces.aiWritable()` assigns: a whole leaf of `.webpieces/` either lives in the worktree or
101
- * it does not. A nested `pr-review/` under some other home is ordinary legacy state.
102
- */
103
- drain(legacyRoot, targetRoot, relative, report, keepInPlace) {
104
- const from = path.join(legacyRoot, relative);
105
- for (const entry of fs.readdirSync(from, { withFileTypes: true })) {
106
- if (relative === '' && keepInPlace.has(entry.name))
107
- continue;
108
- const childRelative = path.join(relative, entry.name);
109
- const source = path.join(legacyRoot, childRelative);
110
- const destination = path.join(targetRoot, childRelative);
111
- if (!fs.existsSync(destination)) {
112
- this.relocate(source, destination, childRelative, report);
113
- continue;
114
- }
115
- if (entry.isDirectory() && fs.statSync(destination).isDirectory()) {
116
- this.drain(legacyRoot, targetRoot, childRelative, report, keepInPlace);
117
- this.removeIfEmpty(source);
118
- continue;
119
- }
120
- report.kept.push(childRelative);
121
- }
122
- }
123
- // Move one file or subtree to a free destination. `rename` first (atomic, instant, and the only
124
- // form that cannot half-move a merge); a cross-device rename falls back to copy-then-remove.
125
- relocate(source, destination, relative, report) {
126
- fs.mkdirSync(path.dirname(destination), { recursive: true });
127
- // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
128
- try {
129
- fs.renameSync(source, destination);
130
- }
131
- catch (err) {
132
- const error = (0, to_error_1.toError)(err);
133
- void error;
134
- fs.cpSync(source, destination, { recursive: true });
135
- fs.rmSync(source, { recursive: true, force: true });
136
- }
137
- report.moved.push(relative);
138
- }
139
- // A real directory, not a symlink to one — `lstat` on purpose. A symlink here is the NEW scheme
140
- // already in place, and following it would make the migrator try to drain a directory into itself.
141
- isRealDirectory(dir) {
142
- // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
143
- try {
144
- return fs.lstatSync(dir).isDirectory();
145
- }
146
- catch (err) {
147
- const error = (0, to_error_1.toError)(err);
148
- void error;
149
- return false;
150
- }
151
- }
152
- // Remove a directory only when it is genuinely empty. Never recursive — a non-empty legacy dir is
153
- // state a human still needs.
154
- removeIfEmpty(dir) {
155
- // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
156
- try {
157
- if (!fs.existsSync(dir))
158
- return;
159
- if (fs.readdirSync(dir).length > 0)
160
- return;
161
- fs.rmdirSync(dir);
162
- }
163
- catch (err) {
164
- const error = (0, to_error_1.toError)(err);
165
- void error;
166
- }
167
- }
168
- // Migration is invisible by design when it goes cleanly; anything LEFT BEHIND must be shouted about,
169
- // because that is the only case where a human has to do something.
170
- announce(legacyDir, targetDir, report) {
171
- if (report.kept.length === 0)
172
- return;
173
- this.warn(`${String(report.kept.length)} item(s) in ${legacyDir} could NOT move into ${targetDir} because ` +
174
- `that path is already occupied. NOTHING was deleted — resolve by hand if any of these still ` +
175
- `matters (an in-flight merge, or log history you have not read): ${report.kept.join(', ')}`);
176
- }
177
- warn(message) {
178
- process.stderr.write(`[webpieces] .webpieces state migration: ${message}\n`);
179
- }
180
- };
181
- exports.StateDirMigrator = StateDirMigrator;
182
- exports.StateDirMigrator = StateDirMigrator = tslib_1.__decorate([
183
- (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton)
184
- ], StateDirMigrator);
185
- //# sourceMappingURL=state-dir-migration.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"state-dir-migration.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/state-dir-migration.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,mDAA6B;AAC7B,yCAA2D;AAE3D,yCAAqC;AAErC;;;;;GAKG;AACH,MAAa,oBAAoB;IAC7B,KAAK,GAAa,EAAE,CAAC;IACrB,IAAI,GAAa,EAAE,CAAC;IAEpB,IAAI,aAAa;QACb,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;IACjC,CAAC;CACJ;AAPD,oDAOC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEI,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IACzB;;;;;;;;;OASG;IACH,OAAO,CAAC,SAAiB,EAAE,SAAiB,EAAE,WAA8B;QACxE,MAAM,MAAM,GAAG,IAAI,oBAAoB,EAAE,CAAC;QAC1C,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;YAAE,OAAO,MAAM,CAAC;QAEvE,8DAA8D;QAC9D,IAAI,CAAC;YACD,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC;gBAAE,OAAO,MAAM,CAAC;YACpD,EAAE,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAC7C,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC;YACnE,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;QAClC,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;YAC3B,IAAI,CAAC,IAAI,CAAC,qBAAqB,SAAS,SAAS,SAAS,K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AAC,GAAW;QAC7B,8DAA8D;QAC9D,IAAI,CAAC;YACD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC;gBAAE,OAAO;YAChC,IAAI,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC;gBAAE,OAAO;YAC3C,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QACtB,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;YAC3B,KAAK,KAAK,CAAC;QACf,CAAC;IACL,CAAC;IAED,qGAAqG;IACrG,mEAAmE;IAC3D,QAAQ,CAAC,SAAiB,EAAE,SAAiB,EAAE,MAA4B;QAC/E,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO;QACrC,IAAI,CAAC,IAAI,CACL,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,eAAe,SAAS,wBAAwB,SAAS,WAAW;YACjG,6FAA6F;YAC7F,mEAAmE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAC9F,CAAC;IACN,CAAC;IAEO,IAAI,CAAC,OAAe;QACxB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,2CAA2C,OAAO,IAAI,CAAC,CAAC;IACjF,CAAC;CACJ,CAAA;AA5HY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,gBAAgB,CA4H5B","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 * What a migration did. Data-only (per CLAUDE.md: classes for data, explicit construction).\n *\n * `kept` is the important half: an entry that could NOT be moved because the destination already holds\n * something at that path. Nothing in `kept` is ever deleted — it stays where it is, for a human.\n */\nexport class StateMigrationReport {\n moved: string[] = [];\n kept: string[] = [];\n\n get movedAnything(): boolean {\n return this.moved.length > 0;\n }\n}\n\n/**\n * Moves a LEGACY per-worktree `.webpieces/` REAL DIRECTORY into the worktree's namespace inside the\n * primary clone (`<primary>/.webpieces/worktrees/<name>/`).\n *\n * NO SYMLINK IS EVER CREATED in its place — an earlier draft of this design planned one and this\n * comment still said so, which is worse than silence: it told the reader to expect an indirection\n * that does not exist. `DotWebpieces` resolves the namespace path EXPLICITLY (see its \"Why two\n * explicit methods and not a symlink\" section, which records why the link was rejected: lazy creation\n * with three failure modes, a Windows hazard, and `rename(2)` silently REPLACING the link). After a\n * migration the legacy `<worktree>/.webpieces/` is simply gone; nothing takes its place.\n *\n * WHY it must exist: those directories hold REAL in-flight state — above all a half-finished 3-point\n * merge under `merge-info/staged/<branch>/`. The first invocation under the new scheme must not orphan\n * them; a merge an agent is standing in the middle of is not recoverable by re-running anything.\n *\n * WHAT IT MUST NOT TOUCH: the `keepInPlace` leaves — `pr-review/` today. Those are not legacy at all;\n * `DotWebpieces.aiWritable()` resolves them to the worktree root ON PURPOSE, because that is the only\n * directory a worktree-isolated coding agent is permitted to write into. Draining one would delete the\n * live review directory out from under the agent writing it.\n *\n * WHY a plain move suffices: the destination namespace is created FOR this worktree, so it is empty in\n * the ordinary case and the whole tree moves in one `rename`. Where something is already there (a\n * repeat run, or an old PUBLISHED build having written to the legacy path again mid-transition), we\n * descend and move only what is free.\n *\n * SAFETY RULE, absolute: this never deletes or overwrites anything that holds content. If a\n * destination path is occupied, the legacy copy is LEFT WHERE IT IS and reported loudly on stderr.\n * Empty directories are removed as they drain, which is how a fully-migrated legacy `.webpieces/`\n * disappears on its own and lets the symlink be created.\n *\n * It is also the answer to the PUBLISHED-vs-LOCAL transition window. The `wp-*` bins and the hooks run\n * the PUBLISHED package, so for a while some invocations still create a REAL `<worktree>/.webpieces`\n * directory. Because this runs on the first state-dir resolution of EVERY new-code process, anything an\n * old-code invocation deposited is swept into the worktree namespace before any reader looks — and a\n * reader running old code finds it through the symlink either way. The two schemes converge instead of\n * splitting; nothing is lost in either direction.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class StateDirMigrator {\n /**\n * Drain `legacyDir` into `targetDir`. A no-op when they are the same directory or when the legacy\n * dir does not exist / is not a real directory (a symlink means migration already happened).\n *\n * `keepInPlace` names the TOP-LEVEL leaves of `legacyDir` that are NOT legacy — the ones\n * `DotWebpieces.aiWritable()` deliberately resolves to the worktree's own root because a\n * worktree-isolated coding agent cannot write anywhere else (today: `pr-review/`). Sweeping those\n * into the namespace would move a live directory out from under the agent that is mid-way through\n * writing it, so they are skipped and NOT reported as kept — nothing about them is unresolved.\n */\n migrate(legacyDir: string, targetDir: string, keepInPlace: readonly string[]): StateMigrationReport {\n const report = new StateMigrationReport();\n if (path.resolve(legacyDir) === path.resolve(targetDir)) return report;\n\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n if (!this.isRealDirectory(legacyDir)) return report;\n fs.mkdirSync(targetDir, { recursive: true });\n this.drain(legacyDir, targetDir, '', report, new Set(keepInPlace));\n this.removeIfEmpty(legacyDir);\n } catch (err: unknown) {\n const error = toError(err);\n this.warn(`could not migrate ${legacyDir} into ${targetDir}: ${error.message}`);\n return report;\n }\n\n this.announce(legacyDir, targetDir, report);\n return report;\n }\n\n /**\n * Move everything under `<legacyRoot>/<relative>` to `<targetRoot>/<relative>`.\n *\n * A whole subtree whose destination is free moves in ONE `rename` — which is what keeps an\n * in-flight `merge-info/staged/<branch>/` intact rather than copying it file by file and risking a\n * half-moved merge. Only when the destination is an existing DIRECTORY do we descend and consider\n * its children individually.\n *\n * `keepInPlace` is consulted at the TOP LEVEL only (`relative === ''`), because that is the scope\n * `DotWebpieces.aiWritable()` assigns: a whole leaf of `.webpieces/` either lives in the worktree or\n * it does not. A nested `pr-review/` under some other home is ordinary legacy state.\n */\n private drain(\n legacyRoot: string, targetRoot: string, relative: string, report: StateMigrationReport,\n keepInPlace: ReadonlySet<string>,\n ): void {\n const from = path.join(legacyRoot, relative);\n for (const entry of fs.readdirSync(from, { withFileTypes: true })) {\n if (relative === '' && keepInPlace.has(entry.name)) continue;\n const childRelative = path.join(relative, entry.name);\n const source = path.join(legacyRoot, childRelative);\n const destination = path.join(targetRoot, childRelative);\n\n if (!fs.existsSync(destination)) {\n this.relocate(source, destination, childRelative, report);\n continue;\n }\n if (entry.isDirectory() && fs.statSync(destination).isDirectory()) {\n this.drain(legacyRoot, targetRoot, childRelative, report, keepInPlace);\n this.removeIfEmpty(source);\n continue;\n }\n report.kept.push(childRelative);\n }\n }\n\n // Move one file or subtree to a free destination. `rename` first (atomic, instant, and the only\n // form that cannot half-move a merge); a cross-device rename falls back to copy-then-remove.\n private relocate(source: string, destination: string, relative: string, report: StateMigrationReport): void {\n fs.mkdirSync(path.dirname(destination), { recursive: true });\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n fs.renameSync(source, destination);\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n fs.cpSync(source, destination, { recursive: true });\n fs.rmSync(source, { recursive: true, force: true });\n }\n report.moved.push(relative);\n }\n\n // A real directory, not a symlink to one — `lstat` on purpose. A symlink here is the NEW scheme\n // already in place, and following it would make the migrator try to drain a directory into itself.\n private isRealDirectory(dir: string): boolean {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return fs.lstatSync(dir).isDirectory();\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return false;\n }\n }\n\n // Remove a directory only when it is genuinely empty. Never recursive — a non-empty legacy dir is\n // state a human still needs.\n private removeIfEmpty(dir: string): void {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n if (!fs.existsSync(dir)) return;\n if (fs.readdirSync(dir).length > 0) return;\n fs.rmdirSync(dir);\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n }\n }\n\n // Migration is invisible by design when it goes cleanly; anything LEFT BEHIND must be shouted about,\n // because that is the only case where a human has to do something.\n private announce(legacyDir: string, targetDir: string, report: StateMigrationReport): void {\n if (report.kept.length === 0) return;\n this.warn(\n `${String(report.kept.length)} item(s) in ${legacyDir} could NOT move into ${targetDir} because ` +\n `that path is already occupied. NOTHING was deleted — resolve by hand if any of these still ` +\n `matters (an in-flight merge, or log history you have not read): ${report.kept.join(', ')}`,\n );\n }\n\n private warn(message: string): void {\n process.stderr.write(`[webpieces] .webpieces state migration: ${message}\\n`);\n }\n}\n"]}