@yeison.restrepo.r/code-conductor 1.32.1 → 1.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yeison.restrepo.r/code-conductor",
3
- "version": "1.32.1",
3
+ "version": "1.33.0",
4
4
  "description": "A spec-first, token-efficient Claude Code configuration and installer CLI.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -150,15 +150,19 @@ function g3JoinContinuations(input) {
150
150
  return result;
151
151
  }
152
152
 
153
- // The five-state scanner, in two modes. "strip" removes unquoted comments and
154
- // reports malformed input (a state other than UNQUOTED at end of input, meaning an
155
- // unclosed quote). "glob" reports whether an unquoted glob character appears, and
156
- // treats malformed input as a glob, which is the authority's fail-closed choice.
153
+ // The six-state scanner, in two modes. "strip" removes unquoted comments and
154
+ // reports malformed input (a state other than UNQUOTED or HEREDOC at end of input,
155
+ // meaning an unclosed quote). "glob" reports whether an unquoted glob character
156
+ // appears, and treats malformed input as a glob, which is the authority's
157
+ // fail-closed choice. HEREDOC blanks a heredoc body, added under [BUG-047].
157
158
  function g3Scan(mode, input) {
158
159
  const emit = mode === 'strip' || mode === 'mask';
159
160
  let state = 'UNQUOTED';
160
161
  let result = '';
161
162
  let i = 0;
163
+ let hdPending = null; // delimiter recorded at the introducer
164
+ let hdDelim = null; // delimiter in force while state === 'HEREDOC'
165
+ let hdDash = false;
162
166
  const len = input.length;
163
167
  while (i < len) {
164
168
  const ch = input[i];
@@ -169,12 +173,70 @@ function g3Scan(mode, input) {
169
173
  else if (ch === '\\') { if (emit) result += input.slice(i, i + 2); i += 2; }
170
174
  else if (ch === "'") { if (emit) result += ch; i += 1; state = 'SINGLE_QUOTED'; }
171
175
  else if (ch === '"') { if (emit) result += ch; i += 1; state = 'DOUBLE_QUOTED'; }
176
+ else if (two === '<<' && input[i + 2] !== '<') {
177
+ // Heredoc introducer. `<<<` is a HERE-STRING, not a heredoc, and excluding it
178
+ // is load-bearing: `cat <<< [x]` denies P4 today and must keep denying. The
179
+ // body does not begin until after this line's newline, so the delimiter is
180
+ // recorded and the rest of the line keeps being scanned as command text.
181
+ let j = i + 2;
182
+ hdDash = input[j] === '-';
183
+ if (hdDash) j += 1;
184
+ while (input[j] === ' ' || input[j] === '\t') j += 1;
185
+ const q = (input[j] === "'" || input[j] === '"') ? input[j] : '';
186
+ if (q) j += 1;
187
+ let w = '';
188
+ while (j < len && /[A-Za-z0-9_.-]/.test(input[j])) { w += input[j]; j += 1; }
189
+ if (q && input[j] === q) j += 1;
190
+ if (w) {
191
+ // Delimiter quoting is recorded and then IGNORED: this scanner performs no
192
+ // expansion, so <<'EOF' and <<EOF are the same to it. [BUG-047]
193
+ hdPending = w;
194
+ if (emit) result += input.slice(i, j);
195
+ i = j;
196
+ } else {
197
+ if (emit) result += ch;
198
+ i += 1;
199
+ }
200
+ }
172
201
  else if (ch === '#' && mode === 'strip') { while (i < len && input[i] !== '\n') i += 1; }
173
202
  else {
174
203
  if (mode === 'glob' && (ch === '*' || ch === '?' || ch === '{' || ch === '[')) return { glob: true };
175
204
  if (emit) result += ch;
176
205
  i += 1;
206
+ if (ch === '\n' && hdPending !== null) { hdDelim = hdPending; hdPending = null; state = 'HEREDOC'; }
207
+ }
208
+ } else if (state === 'HEREDOC') {
209
+ // One line at a time. Every non-newline body character is blanked to 'x',
210
+ // length-preserved because the P4 and P7 walks slice by match LENGTH.
211
+ //
212
+ // Newlines stay VERBATIM here, unlike quoted regions which mask them. Quoted
213
+ // masking stops a newline inside a string becoming a command-position anchor;
214
+ // here the opposite is needed, because the newline after the terminator must
215
+ // survive or a command following the heredoc loses its command position and a
216
+ // real dump stops denying. Body newlines are harmless: everything around them
217
+ // is 'x'. [BUG-047]
218
+ let eol = input.indexOf('\n', i);
219
+ if (eol === -1) eol = len;
220
+ const line = input.slice(i, eol);
221
+ const cmp = hdDash ? line.replace(/^\t+/, '') : line;
222
+ // Only a line EQUAL to the delimiter terminates. A substring would end the state
223
+ // early and expose the rest of the body to the patterns.
224
+ //
225
+ // THE TERMINATOR IS EMITTED VERBATIM, and that is load-bearing. guard3BashScan
226
+ // runs this scanner TWICE, building the mask from strip's output, so the
227
+ // transformation has to be IDEMPOTENT. A blanked terminator is unfindable on the
228
+ // second pass: the scanner re-enters HEREDOC at the same introducer, never
229
+ // terminates, and blanks every command after the heredoc. The symptom is a
230
+ // genuine dump following a heredoc silently ceasing to deny. Body lines carry no
231
+ // such requirement, because nothing downstream needs to find them again.
232
+ if (cmp === hdDelim) {
233
+ if (emit) result += line;
234
+ state = 'UNQUOTED'; hdDelim = null; hdDash = false;
235
+ } else if (emit) {
236
+ result += 'x'.repeat(line.length);
177
237
  }
238
+ i = eol;
239
+ if (i < len) { if (emit) result += '\n'; i += 1; }
178
240
  } else if (state === 'SINGLE_QUOTED') {
179
241
  // Backslash is literal here and ANY quote exits: there is no escape mechanism.
180
242
  if (mode === 'strip') result += ch;
@@ -191,7 +253,17 @@ function g3Scan(mode, input) {
191
253
  else { if (mode === 'strip') result += ch; else if (mode === 'mask') result += 'x'; i += 1; }
192
254
  }
193
255
  }
194
- if (state !== 'UNQUOTED') return emit ? { result, malformed: true } : { glob: true };
256
+ // HEREDOC is deliberately exempt from the fail-closed check, and the exemption must
257
+ // not be "normalised" away. The rule exists because an unbalanced quote leaves
258
+ // AMBIGUITY about where command text resumes, and the scanner refuses to guess. An
259
+ // unterminated heredoc leaves no ambiguity: everything to end of input is body and
260
+ // there is no "after", so there is nothing unread to protect. Bash agrees, measured:
261
+ // on GNU bash 3.2.57, the interpreter the authority runs under, a script ending
262
+ // mid-heredoc delivers the body and exits 0 with NO warning; newer bash also warns
263
+ // and still proceeds. Fail-closed here would deny every draft of a file write whose
264
+ // delimiter line has not arrived yet, which is [BUG-047]'s own defect in a new
265
+ // state. The departure is correct BECAUSE the rule's premise does not apply.
266
+ if (state !== 'UNQUOTED' && state !== 'HEREDOC') return emit ? { result, malformed: true } : { glob: true };
195
267
  return emit ? { result, malformed: false } : { glob: false };
196
268
  }
197
269