wrxn-reversa 1.8.2 → 1.8.3
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.
- package/README.md +4 -1
- package/lib/installer/writer.js +18 -24
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,7 +63,10 @@ The installer will:
|
|
|
63
63
|
> [!IMPORTANT]
|
|
64
64
|
> ### 🔒 Guaranteed immutability of the legacy project
|
|
65
65
|
>
|
|
66
|
-
>
|
|
66
|
+
> Install and update place the full marked routing block at the start of `AGENTS.md`, regardless of file size.
|
|
67
|
+
> They preserve your text and keep edited Reversa blocks unchanged.
|
|
68
|
+
> For other existing instruction files, install asks before it adds a new block.
|
|
69
|
+
> During analysis, agents follow the project's Reversa write policy.
|
|
67
70
|
|
|
68
71
|
> [!CAUTION]
|
|
69
72
|
> ### 💾 Back up your project before starting
|
package/lib/installer/writer.js
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
readdirSync, statSync, chmodSync,
|
|
5
5
|
copyFileSync, unlinkSync,
|
|
6
6
|
} from 'fs';
|
|
7
|
-
import { join, dirname, resolve
|
|
7
|
+
import { join, dirname, resolve } from 'path';
|
|
8
8
|
import { fileURLToPath } from 'url';
|
|
9
9
|
import { askMergeStrategy } from './prompts.js';
|
|
10
10
|
import { readJsonSafe } from '../utils/json-safe.js';
|
|
@@ -18,6 +18,11 @@ const REPO_ROOT = resolve(__dirname, '..', '..');
|
|
|
18
18
|
const AGENTS_DIR = join(REPO_ROOT, 'agents');
|
|
19
19
|
const TEMPLATES_DIR = join(REPO_ROOT, 'templates');
|
|
20
20
|
|
|
21
|
+
function placeEntryBlock(file, text, block, range) {
|
|
22
|
+
if (file !== 'AGENTS.md') return upsertBlock(text, block, range);
|
|
23
|
+
return block + (range ? text.slice(0, range.start) + text.slice(range.end) : text);
|
|
24
|
+
}
|
|
25
|
+
|
|
21
26
|
export class Writer {
|
|
22
27
|
constructor(projectRoot) {
|
|
23
28
|
this.projectRoot = projectRoot;
|
|
@@ -145,7 +150,7 @@ export class Writer {
|
|
|
145
150
|
const text = readFileSync(destPath, 'utf8');
|
|
146
151
|
const found = findBlock(text);
|
|
147
152
|
if (found.status === 'ok' && !found.edited) {
|
|
148
|
-
writeFileSync(destPath,
|
|
153
|
+
writeFileSync(destPath, placeEntryBlock(target.file, text, block, found), 'utf8');
|
|
149
154
|
this.entryBlocks[target.file] = { mode: records[target.file]?.mode ?? 'merged', sha256 };
|
|
150
155
|
return;
|
|
151
156
|
}
|
|
@@ -153,23 +158,15 @@ export class Writer {
|
|
|
153
158
|
console.log(` Kept ${target.file}: Reversa block was edited or its markers are damaged`);
|
|
154
159
|
return;
|
|
155
160
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
this.entryBlocks[target.file] = { mode: 'skipped' };
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
const merged = upsertBlock(text, block);
|
|
164
|
-
if (basename(target.file) === 'AGENTS.md') {
|
|
165
|
-
const bytes = Buffer.byteLength(merged);
|
|
166
|
-
if (bytes > 32768) {
|
|
167
|
-
console.log(" Not merged into AGENTS.md: the result would exceed Codex's 32 KiB project_doc_max_bytes limit.");
|
|
161
|
+
const legacy = target.file === 'AGENTS.md' ? findLegacyBlock(text) : null;
|
|
162
|
+
if (target.file !== 'AGENTS.md') {
|
|
163
|
+
if (records[target.file]?.mode === 'skipped') return;
|
|
164
|
+
if (await askMergeStrategy(target.file) !== 'merge') {
|
|
168
165
|
this.entryBlocks[target.file] = { mode: 'skipped' };
|
|
169
166
|
return;
|
|
170
167
|
}
|
|
171
|
-
if (bytes > 28672) console.log(" Warning: AGENTS.md will be close to Codex's 32 KiB limit.");
|
|
172
168
|
}
|
|
169
|
+
const merged = placeEntryBlock(target.file, text, block, legacy);
|
|
173
170
|
writeFileSync(destPath, merged, 'utf8');
|
|
174
171
|
this.entryBlocks[target.file] = { mode: 'merged', sha256 };
|
|
175
172
|
}
|
|
@@ -436,7 +433,7 @@ export class Writer {
|
|
|
436
433
|
const state = pathState(this.projectRoot, rel);
|
|
437
434
|
const dropKey = index.get(rel)?.key;
|
|
438
435
|
if (state === 'missing') {
|
|
439
|
-
if (records[rel]?.mode === 'skipped') return;
|
|
436
|
+
if (rel !== 'AGENTS.md' && records[rel]?.mode === 'skipped') return;
|
|
440
437
|
const restore = records[rel]?.mode === 'created' || index.has(rel);
|
|
441
438
|
if (restore || addOnUpdate) {
|
|
442
439
|
plan.writes.push({ rel, reason: restore ? 'restore' : 'new', content: block, block: { mode: 'created', sha256 }, dropKey });
|
|
@@ -451,9 +448,10 @@ export class Writer {
|
|
|
451
448
|
const baseline = hashContent(text);
|
|
452
449
|
const found = findBlock(text);
|
|
453
450
|
if (found.status === 'ok' && !found.edited) {
|
|
454
|
-
|
|
451
|
+
const content = placeEntryBlock(rel, text, block, found);
|
|
452
|
+
if (content === text) return;
|
|
455
453
|
plan.writes.push({
|
|
456
|
-
rel, reason: 'refresh', content
|
|
454
|
+
rel, reason: 'refresh', content, baseline,
|
|
457
455
|
block: { mode: records[rel]?.mode ?? 'merged', sha256 }, dropKey,
|
|
458
456
|
});
|
|
459
457
|
} else if (found.status === 'ok') {
|
|
@@ -468,12 +466,8 @@ export class Writer {
|
|
|
468
466
|
plan.kept.push({ rel, reason: 'damaged markers' });
|
|
469
467
|
} else {
|
|
470
468
|
const legacy = findLegacyBlock(text);
|
|
471
|
-
if (!legacy && (!addOnUpdate || records[rel]?.mode === 'skipped')) return;
|
|
472
|
-
const content =
|
|
473
|
-
if (rel === 'AGENTS.md' && Buffer.byteLength(content) > 32768) {
|
|
474
|
-
plan.kept.push({ rel, reason: "would exceed Codex's 32 KiB project_doc_max_bytes limit" });
|
|
475
|
-
return;
|
|
476
|
-
}
|
|
469
|
+
if (!legacy && (!addOnUpdate || (rel !== 'AGENTS.md' && records[rel]?.mode === 'skipped'))) return;
|
|
470
|
+
const content = placeEntryBlock(rel, text, block, legacy);
|
|
477
471
|
plan.writes.push({
|
|
478
472
|
rel, reason: legacy ? 'migrate' : 'refresh', content, baseline,
|
|
479
473
|
block: { mode: index.has(rel) && legacy?.start === 0 ? 'created' : 'merged', sha256 }, dropKey,
|