deuk-agent-rule 2.5.13 → 2.5.14

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/CHANGELOG.md CHANGED
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [2.5.14] - 2026-04-22
8
+
9
+
10
+ ### Fixed
11
+
12
+ - **cli:** resolve marker nesting bug in AGENTS.md injection
13
+
7
14
  ## [2.5.13] - 2026-04-22
8
15
 
9
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deuk-agent-rule",
3
- "version": "2.5.13",
3
+ "version": "2.5.14",
4
4
  "description": "DeukAgentRules: generic AGENTS.md + .cursor rule templates with init/merge CLI (npm name: deuk-agent-rule).",
5
5
  "keywords": [
6
6
  "agents-md",
@@ -41,11 +41,27 @@ export function resolveMarkers(o) {
41
41
  };
42
42
  }
43
43
 
44
+ /**
45
+ * Strip all internal begin/end marker lines from content.
46
+ * Preserves only the content between markers without nesting.
47
+ */
48
+ export function stripInternalMarkers(content, begin, end) {
49
+ return content
50
+ .split('\n')
51
+ .filter(line => {
52
+ const t = line.trim();
53
+ return t !== begin && t !== end;
54
+ })
55
+ .join('\n');
56
+ }
57
+
44
58
  export function findMarkerRegion(content, begin, end) {
45
59
  const i = content.indexOf(begin);
46
60
  if (i === -1) return null;
47
- const j = content.indexOf(end, i + begin.length);
48
- if (j === -1) {
61
+ // Use lastIndexOf to match the outermost end marker,
62
+ // preventing nested markers from causing partial replacement.
63
+ const j = content.lastIndexOf(end);
64
+ if (j === -1 || j <= i) {
49
65
  throw new Error(
50
66
  `[MARKER ERROR] Found begin marker "${begin}" but no matching end marker "${end}" after it.\n` +
51
67
  ` This usually happens if one marker was deleted or renamed manually. Please verify the target file.`
@@ -120,8 +136,10 @@ function handleAgentOverwrite(opts) {
120
136
  }
121
137
 
122
138
  function handleAgentInject(opts, existing, region) {
123
- const { targetPath, bundleContent, dryRun, backup } = opts;
124
- const inner = bundleContent.trimEnd() + "\n";
139
+ const { targetPath, bundleContent, markers, dryRun, backup } = opts;
140
+ // Strip any internal begin/end markers from bundle content to prevent nesting
141
+ const cleanContent = stripInternalMarkers(bundleContent, markers.begin, markers.end);
142
+ const inner = cleanContent.trimEnd() + "\n";
125
143
  const next = existing.slice(0, region.innerStart) + "\n" + inner + existing.slice(region.innerEnd);
126
144
  if (dryRun) {
127
145
  return { action: "would-write", path: targetPath, mode: "inject-region" };