@code-yeongyu/senpi-codemode 2026.8.29 → 2026.8.30-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/CHANGELOG.md CHANGED
@@ -12,6 +12,68 @@
12
12
 
13
13
  ### Removed
14
14
 
15
+ ## [2026.8.30-3] - 2026-08-30
16
+
17
+ ### Breaking Changes
18
+
19
+ ### Added
20
+
21
+ ### Changed
22
+
23
+ ### Fixed
24
+
25
+ ### Removed
26
+
27
+ ## [2026.8.30-2] - 2026-08-30
28
+
29
+ ### Breaking Changes
30
+
31
+ ### Added
32
+
33
+ ### Changed
34
+
35
+ ### Fixed
36
+
37
+ ### Removed
38
+
39
+ ## [2026.8.30] - 2026-08-30
40
+
41
+ ### Breaking Changes
42
+
43
+ ### Added
44
+
45
+ ### Changed
46
+
47
+ - The eval prompt's dependency-graph section is now `<workflow>` and states its contract directly:
48
+ define the workflow spec in code, one node per logically distinct step, rather than hand-authoring
49
+ the graph as a single opaque call.
50
+
51
+ ### Fixed
52
+
53
+ - The JavaScript kernel persistence transform no longer truncates declarations whose multi-line
54
+ initializers contain interior `//` comments (previously emitted unparseable code such as
55
+ `globalThis["jobs"] = {;`, failing cells with `Unexpected token ';'. Expected a property name.`),
56
+ and no longer re-evaluates comment-bearing initializers when persisting bindings — such
57
+ declarations are kept verbatim and their bindings persisted by reference.
58
+ - Last-expression capture no longer inserts `return` before continuation lines (`else`/`catch`/`finally`
59
+ clauses and leading-`.`/operator method-chain lines), and now scans template literals (including
60
+ nested templates in interpolations), regexes, and comments with the same literal-aware scanner as
61
+ the persistence transform — fixing `return else …`, `return .replace(…)`, and mid-argument
62
+ `return )` corruption of valid cells.
63
+ - Last-expression capture now follows real ASI statement semantics: a parenthesized/bracketed/template
64
+ line after a closed block starts a new statement (echo restored), expressions split after a trailing
65
+ operator or `await` stay one statement, tagged templates split across lines invoke the tag, regexes
66
+ directly after a control-structure condition no longer desync the scanner, and labeled final
67
+ statements are left uncaptured instead of emitting invalid `return label: …`.
68
+ - Destructuring patterns carrying interior line comments now persist their bindings, and declarations
69
+ with a dangling trailing comma are left untransformed so the original syntax error surfaces instead
70
+ of being silently "repaired".
71
+ - Rewritten destructuring assignments are emitted with a leading defensive semicolon so they can no
72
+ longer ASI-merge into a preceding unterminated expression statement as a bogus call
73
+ (`foo()\n({…} = …)` previously became `foo()({…} = …)`).
74
+
75
+ ### Removed
76
+
15
77
  ## [2026.8.29] - 2026-08-29
16
78
 
17
79
  ### Breaking Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-yeongyu/senpi-codemode",
3
- "version": "2026.8.29",
3
+ "version": "2026.8.30-3",
4
4
  "description": "Source-only senpi extension package for codemode evaluation tools",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -30,14 +30,14 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@babel/parser": "8.0.4",
33
- "@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.8.29",
33
+ "@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.8.30-3",
34
34
  "typebox": "1.3.18"
35
35
  },
36
36
  "peerDependencies": {
37
- "@code-yeongyu/senpi": "2026.8.29"
37
+ "@code-yeongyu/senpi": "2026.8.30-3"
38
38
  },
39
39
  "devDependencies": {
40
- "@code-yeongyu/senpi": "2026.8.29"
40
+ "@code-yeongyu/senpi": "2026.8.30-3"
41
41
  },
42
42
  "keywords": [
43
43
  "senpi",
@@ -258,20 +258,22 @@ function rewriteDeclaration(code, declarationStart, start, end, keyword) {
258
258
  const preserveDeclaration = source.includes("//") || source.includes("/*");
259
259
  for (const [segmentStart, segmentEnd] of splitDeclarators(code, start, end)) {
260
260
  const segment = code.slice(segmentStart, segmentEnd);
261
- if (!segment.trim()) continue;
261
+ if (!segment.trim()) return undefined;
262
262
  const initializerStart = findTopLevelEquals(segment);
263
263
  if (initializerStart < 0 && keyword === "const") return undefined;
264
264
  const pattern = trimPattern(initializerStart < 0 ? segment : segment.slice(0, initializerStart));
265
265
  const bindings = [];
266
266
  collectPatternNames(pattern, bindings);
267
267
  if (bindings.length === 0) return undefined;
268
+ if (preserveDeclaration) {
269
+ for (const name of bindings) assignments.push(`globalThis[${JSON.stringify(name)}] = ${name};`);
270
+ continue;
271
+ }
268
272
  const target = rewriteBindingPattern(pattern);
269
273
  if (target === undefined) return undefined;
270
274
  const initializer = initializerStart < 0 ? "undefined" : segment.slice(initializerStart + 1).trim();
271
- const [assignmentInitializer, comment] = splitTrailingLineComment(initializer);
272
- const assignmentComment = preserveDeclaration ? "" : comment;
273
275
  assignments.push(
274
- `${target.startsWith("{") || target.startsWith("[") ? `(${target} = ${assignmentInitializer})` : `${target} = ${assignmentInitializer}`};${assignmentComment}`,
276
+ `${target.startsWith("{") || target.startsWith("[") ? `;(${target} = ${initializer})` : `${target} = ${initializer}`};`,
275
277
  );
276
278
  }
277
279
  if (assignments.length === 0) return undefined;
@@ -408,6 +410,7 @@ function splitDeclarators(code, start, end) {
408
410
  if (!/\s/u.test(char)) canStartRegex = isExpressionOperator(char) || char === "(" || char === "[" || char === "{";
409
411
  }
410
412
  if (segmentStart < end && code.slice(segmentStart, end).trim() !== ";") ranges.push([segmentStart, end - (code[end - 1] === ";" ? 1 : 0)]);
413
+ else if (ranges.length > 0 && code.slice(segmentStart, end).trim() !== ";") ranges.push([end, end]);
411
414
  return ranges;
412
415
  }
413
416
 
@@ -501,51 +504,9 @@ function applyTextEdits(code, edits) {
501
504
  return output;
502
505
  }
503
506
 
504
- function splitTrailingLineComment(source) {
505
- let canStartRegex = true;
506
- for (let index = 0; index < source.length; index += 1) {
507
- const char = source[index];
508
- const next = source[index + 1];
509
- if (char === "/" && next === "/") return [source.slice(0, index).trimEnd(), source.slice(index)];
510
- if (char === "/" && next === "*") {
511
- index = skipBlockComment(source, index) - 1;
512
- continue;
513
- }
514
- if (char === "'" || char === '"') {
515
- index = skipQuotedLiteral(source, index) - 1;
516
- canStartRegex = false;
517
- continue;
518
- }
519
- if (char === "`") {
520
- index = skipTemplateLiteral(source, index) - 1;
521
- canStartRegex = false;
522
- continue;
523
- }
524
- if (char === "/" && canStartRegex) {
525
- index = skipRegexLiteral(source, index) - 1;
526
- canStartRegex = false;
527
- continue;
528
- }
529
- if (isIdentifierStart(char)) {
530
- const end = readIdentifier(source, index);
531
- canStartRegex = REGEX_PREFIX_KEYWORDS.has(source.slice(index, end));
532
- index = end - 1;
533
- continue;
534
- }
535
- if (isDecimalDigit(char)) {
536
- index = skipNumberLiteral(source, index) - 1;
537
- canStartRegex = false;
538
- continue;
539
- }
540
- if (!/\s/u.test(char)) canStartRegex = isExpressionOperator(char) || char === "(" || char === "[" || char === "{";
541
- }
542
- return [source, ""];
543
- }
544
-
545
507
  function trimPattern(source) {
546
508
  let start = 0;
547
- let end = source.length;
548
- while (start < end) {
509
+ while (start < source.length) {
549
510
  if (/\s/u.test(source[start])) {
550
511
  start += 1;
551
512
  continue;
@@ -560,12 +521,30 @@ function trimPattern(source) {
560
521
  }
561
522
  break;
562
523
  }
563
- while (true) {
564
- while (end > start && /\s/u.test(source[end - 1])) end -= 1;
565
- if (end < start + 2 || source.slice(end - 2, end) !== "*/") break;
566
- const commentStart = source.lastIndexOf("/*", end - 2);
567
- if (commentStart < start) break;
568
- end = commentStart;
524
+ let end = start;
525
+ for (let index = start; index < source.length; index += 1) {
526
+ const char = source[index];
527
+ const next = source[index + 1];
528
+ if (/\s/u.test(char)) continue;
529
+ if (char === "/" && next === "/") {
530
+ index = skipLineComment(source, index) - 1;
531
+ continue;
532
+ }
533
+ if (char === "/" && next === "*") {
534
+ index = skipBlockComment(source, index) - 1;
535
+ continue;
536
+ }
537
+ if (char === "'" || char === '"') {
538
+ index = skipQuotedLiteral(source, index) - 1;
539
+ end = index + 1;
540
+ continue;
541
+ }
542
+ if (char === "`") {
543
+ index = skipTemplateLiteral(source, index) - 1;
544
+ end = index + 1;
545
+ continue;
546
+ }
547
+ end = index + 1;
569
548
  }
570
549
  return source.slice(start, end);
571
550
  }
@@ -733,66 +712,136 @@ function captureLastExpression(code) {
733
712
  return `${head}return ${tail.replace(/;+$/u, "")};`;
734
713
  }
735
714
 
715
+ const LABEL_PREFIX_RE = /^[\p{ID_Start}$_][\p{ID_Continue}\u200c\u200d$]*\s*:/u;
716
+
736
717
  function isStatementOnly(source) {
737
- return /^(?:const|let|var|if|for|while|switch|try|catch|finally|class|function|import|export|throw|return|do|break|continue|debugger)\b/u.test(
738
- source,
739
- );
718
+ if (
719
+ /^(?:const|let|var|if|for|while|switch|try|catch|finally|class|function|import|export|throw|return|do|break|continue|debugger)\b/u.test(
720
+ source,
721
+ )
722
+ )
723
+ return true;
724
+ return LABEL_PREFIX_RE.test(source);
740
725
  }
741
726
 
727
+ const CONTROL_PAREN_KEYWORDS = new Set(["catch", "for", "if", "switch", "while", "with"]);
728
+
742
729
  function findLastTopLevelStatementStart(code) {
743
730
  let start = 0;
744
731
  let round = 0;
745
732
  let square = 0;
746
733
  let curly = 0;
747
- let quote = "";
748
- let escaped = false;
749
- let lineComment = false;
750
- let blockComment = false;
734
+ let canStartRegex = true;
735
+ let lastSignificant = "";
736
+ let pendingControlParen = false;
737
+ const controlParens = [];
751
738
  for (let index = 0; index < code.length; index += 1) {
752
739
  const char = code[index];
753
740
  const next = code[index + 1];
754
- if (lineComment) {
755
- if (char === "\n") lineComment = false;
741
+ if (char === "/" && next === "/") {
742
+ index = skipLineComment(code, index) - 1;
756
743
  continue;
757
744
  }
758
- if (blockComment) {
759
- if (char === "*" && next === "/") {
760
- blockComment = false;
761
- index += 1;
762
- }
745
+ if (char === "/" && next === "*") {
746
+ index = skipBlockComment(code, index) - 1;
763
747
  continue;
764
748
  }
765
- if (quote) {
766
- if (escaped) {
767
- escaped = false;
768
- } else if (char === "\\") {
769
- escaped = true;
770
- } else if (char === quote) {
771
- quote = "";
772
- }
749
+ if (char === "'" || char === '"' || char === "`") {
750
+ index = (char === "`" ? skipTemplateLiteral(code, index) : skipQuotedLiteral(code, index)) - 1;
751
+ canStartRegex = false;
752
+ lastSignificant = char;
753
+ pendingControlParen = false;
773
754
  continue;
774
755
  }
775
- if (char === "/" && next === "/") {
776
- lineComment = true;
777
- index += 1;
756
+ if (char === "/" && canStartRegex) {
757
+ index = skipRegexLiteral(code, index) - 1;
758
+ canStartRegex = false;
759
+ lastSignificant = char;
760
+ pendingControlParen = false;
778
761
  continue;
779
762
  }
780
- if (char === "/" && next === "*") {
781
- blockComment = true;
782
- index += 1;
763
+ if (isIdentifierStart(char)) {
764
+ const end = readIdentifier(code, index);
765
+ const token = code.slice(index, end);
766
+ canStartRegex = REGEX_PREFIX_KEYWORDS.has(token);
767
+ pendingControlParen = CONTROL_PAREN_KEYWORDS.has(token);
768
+ lastSignificant = code[end - 1];
769
+ index = end - 1;
783
770
  continue;
784
771
  }
785
- if (char === "'" || char === '"' || char === "`") {
786
- quote = char;
772
+ if (isDecimalDigit(char)) {
773
+ index = skipNumberLiteral(code, index) - 1;
774
+ canStartRegex = false;
775
+ lastSignificant = char;
776
+ pendingControlParen = false;
787
777
  continue;
788
778
  }
789
- if (char === "(") round += 1;
790
- else if (char === ")") round -= 1;
791
- else if (char === "[") square += 1;
792
- else if (char === "]") square -= 1;
793
- else if (char === "{") curly += 1;
794
- else if (char === "}") curly -= 1;
795
- else if ((char === ";" || char === "\n") && round === 0 && square === 0 && curly === 0) start = index + 1;
779
+ if (char === "(") {
780
+ round += 1;
781
+ controlParens.push(pendingControlParen);
782
+ pendingControlParen = false;
783
+ canStartRegex = true;
784
+ lastSignificant = char;
785
+ continue;
786
+ }
787
+ if (char === ")") {
788
+ round = Math.max(0, round - 1);
789
+ canStartRegex = controlParens.pop() === true;
790
+ lastSignificant = char;
791
+ continue;
792
+ }
793
+ if (char === "[" || char === "{") {
794
+ if (char === "[") square += 1;
795
+ else curly += 1;
796
+ canStartRegex = true;
797
+ lastSignificant = char;
798
+ pendingControlParen = false;
799
+ continue;
800
+ }
801
+ if (char === "]" || char === "}") {
802
+ if (char === "]") square = Math.max(0, square - 1);
803
+ else curly = Math.max(0, curly - 1);
804
+ canStartRegex = false;
805
+ lastSignificant = char;
806
+ pendingControlParen = false;
807
+ continue;
808
+ }
809
+ if (char === ";" && round === 0 && square === 0 && curly === 0) {
810
+ const nextIndex = nextSignificantIndex(code, index + 1);
811
+ if (nextIndex < code.length && !isContinuationKeyword(code, nextIndex)) start = nextIndex;
812
+ canStartRegex = true;
813
+ lastSignificant = char;
814
+ pendingControlParen = false;
815
+ continue;
816
+ }
817
+ if (isLineTerminator(char) && round === 0 && square === 0 && curly === 0) {
818
+ if (!canStartRegex) {
819
+ const nextIndex = nextSignificantIndex(code, index + 1);
820
+ if (nextIndex < code.length && !isStatementContinuation(code, nextIndex, lastSignificant)) start = nextIndex;
821
+ }
822
+ canStartRegex = true;
823
+ continue;
824
+ }
825
+ if (!/\s/u.test(char)) {
826
+ canStartRegex = isExpressionOperator(char) || char === ",";
827
+ lastSignificant = char;
828
+ pendingControlParen = false;
829
+ }
796
830
  }
797
831
  return start;
798
832
  }
833
+
834
+ const STATEMENT_CONTINUATION_KEYWORDS = new Set(["catch", "else", "finally"]);
835
+
836
+ function isContinuationKeyword(code, index) {
837
+ if (!isIdentifierStart(code[index])) return false;
838
+ return STATEMENT_CONTINUATION_KEYWORDS.has(code.slice(index, readIdentifier(code, index)));
839
+ }
840
+
841
+ function isStatementContinuation(code, index, previousChar) {
842
+ const char = code[index];
843
+ if (char === "(" || char === "[" || char === "`") return previousChar !== "}" && previousChar !== "";
844
+ if (char === "!" || char === "~") return false;
845
+ if (char !== undefined && isDeclarationContinuation(char)) return true;
846
+ return isContinuationKeyword(code, index);
847
+ }
@@ -163,7 +163,7 @@ tool_schema(name?) → dict
163
163
  completion(prompt, model?="default", system?=None, schema?=None) → str | dict
164
164
  Oneshot, stateless (no history/tools). \`model\`: \`"smol"\` fast | \`"default"\` session | \`"slow"\` most capable. \`schema\` (JSON-Schema) → structured output, parsed object.
165
165
  {{#if spawns}}agent(prompt, agent?="{{spawnDefaultAgent}}", model?=None, label?=None, schema?=None, handle?=False) → str | dict
166
- Run a subagent → final output. \`agent\` picks another discovered agent; omit it to use \`{{spawnDefaultAgent}}\`. \`schema\` as in completion(). Background via \`local://\` files named in the prompt. \`handle\` → DAG node dict { text, output, handle: \`agent://<id>\`, id, agent } (parsed under \`data\` when \`schema\` set).
166
+ Run a subagent → final output. \`agent\` picks another discovered agent; omit it to use \`{{spawnDefaultAgent}}\`. \`schema\` as in completion(). Background via \`local://\` files named in the prompt. \`handle\` → workflow node dict { text, output, handle: \`agent://<id>\`, id, agent } (parsed under \`data\` when \`schema\` set).
167
167
  {{#if js}} JS: options are ONE trailing object — agent(prompt, { agent, schema, handle }).
168
168
  {{/if}}{{/if}}parallel(thunks) → list
169
169
  Thunks through a bounded pool (wide as a \`task\` batch — don't pre-shrink), input order kept; returns when all finish, a throwing thunk propagates.
@@ -176,14 +176,14 @@ phase(title) → None
176
176
  \`\`\`
177
177
  </prelude>
178
178
  {{#if spawns}}
179
- <dag>
180
- Pipe handles through stage helpers to build a dependency graph acyclic waves:
179
+ <workflow>
180
+ Define the workflow spec IN CODE: partition the work into logically distinct steps, one node per step, then wire them as acyclic waves — never hand-author the graph as a single opaque call.
181
181
  - **Name nodes.** Capture each \`agent(…, {{#if py}}handle=True{{/if}}{{#if js}}{ handle: true }{{/if}}{{#if jl}}handle=true{{/if}})\` result; carries \`handle\` (\`agent://<id>\`) + \`output\`.
182
182
  - **Wire edges by reference.** Put an upstream node's \`handle\`/\`output\` in the dependent stage's prompt — large transcript never re-inlined. Bulk: \`write("local://<name>.md", …)\`, pass the URI.
183
183
  - **\`pipeline(items, *stages)\` = staged waves**, barrier between stages (every item clears stage N before any enters N+1). **\`parallel(thunks)\` = one wave** of independent nodes.
184
184
  - **Isolate failure.** A raising node re-raises the lowest-index error, aborts its wave; wrap risky nodes in try/except so a failure degrades only its dependent subtree, independent branches finish.
185
185
  - **Acyclic only.** A node never waits on its own descendant.
186
- </dag>
186
+ </workflow>
187
187
  {{/if}}
188
188
 
189
189
  <critical>