gsd-pi 2.33.1-dev.9bafd68 → 2.33.1-dev.bf822e6
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/dist/resource-loader.js +3 -1
- package/dist/resources/extensions/gsd/auto-worktree.js +71 -0
- package/dist/resources/extensions/gsd/auto.js +11 -1
- package/package.json +1 -1
- package/packages/pi-ai/dist/models.generated.d.ts +5498 -3645
- package/packages/pi-ai/dist/models.generated.d.ts.map +1 -1
- package/packages/pi-ai/dist/models.generated.js +2595 -742
- package/packages/pi-ai/dist/models.generated.js.map +1 -1
- package/packages/pi-ai/src/models.generated.ts +2852 -999
- package/packages/pi-coding-agent/dist/core/agent-session.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/agent-session.js +9 -0
- package/packages/pi-coding-agent/dist/core/agent-session.js.map +1 -1
- package/packages/pi-coding-agent/src/core/agent-session.ts +9 -0
- package/packages/pi-tui/dist/utils.d.ts.map +1 -1
- package/packages/pi-tui/dist/utils.js +32 -2
- package/packages/pi-tui/dist/utils.js.map +1 -1
- package/packages/pi-tui/src/utils.ts +28 -2
- package/src/resources/extensions/gsd/auto-worktree.ts +71 -0
- package/src/resources/extensions/gsd/auto.ts +11 -0
- package/src/resources/extensions/gsd/tests/repo-identity-worktree.test.ts +4 -4
|
@@ -1359,6 +1359,15 @@ export class AgentSession {
|
|
|
1359
1359
|
this.abortRetry();
|
|
1360
1360
|
this.agent.abort();
|
|
1361
1361
|
await this.agent.waitForIdle();
|
|
1362
|
+
// Ensure agent_end is emitted even when abort interrupts a tool call (#1414).
|
|
1363
|
+
// The agent may go idle without emitting agent_end if the abort happens
|
|
1364
|
+
// between tool execution and response processing.
|
|
1365
|
+
if (!this.isStreaming && this._extensionRunner) {
|
|
1366
|
+
await this._extensionRunner.emit({
|
|
1367
|
+
type: "agent_end",
|
|
1368
|
+
messages: this.agent.state.messages,
|
|
1369
|
+
});
|
|
1370
|
+
}
|
|
1362
1371
|
}
|
|
1363
1372
|
|
|
1364
1373
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAYA;;GAEG;AACH,wBAAgB,YAAY,IAAI,IAAI,CAAC,SAAS,CAE7C;AAID;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAsCjG;AAMD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAYA;;GAEG;AACH,wBAAgB,YAAY,IAAI,IAAI,CAAC,SAAS,CAE7C;AAID;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAsCjG;AAMD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAOhD;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAuBtE;AAaD;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAC9B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,QAAQ,GAAE,MAAc,EACxB,GAAG,GAAE,OAAe,GAClB,MAAM,CAER;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,UAAQ,GAAG,MAAM,CAEpG;AAED,kFAAkF;AAClF,wBAAgB,cAAc,CAC7B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,MAAM,UAAQ,GACZ;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAEjC;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC9B,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,WAAW,UAAQ,GACjB;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAE5E;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAOzG"}
|
|
@@ -72,7 +72,13 @@ export function extractAnsiCode(str, pos) {
|
|
|
72
72
|
* Delegates to the native Rust implementation.
|
|
73
73
|
*/
|
|
74
74
|
export function visibleWidth(str) {
|
|
75
|
-
|
|
75
|
+
try {
|
|
76
|
+
return nativeVisibleWidth(str);
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
// JS fallback — strip ANSI codes and return length (#1418)
|
|
80
|
+
return str.replace(/\x1b\[[0-9;]*m/g, "").length;
|
|
81
|
+
}
|
|
76
82
|
}
|
|
77
83
|
/**
|
|
78
84
|
* Wrap text with ANSI codes preserved.
|
|
@@ -83,7 +89,31 @@ export function visibleWidth(str) {
|
|
|
83
89
|
* @returns Array of wrapped lines (NOT padded to width)
|
|
84
90
|
*/
|
|
85
91
|
export function wrapTextWithAnsi(text, width) {
|
|
86
|
-
|
|
92
|
+
try {
|
|
93
|
+
return nativeWrapTextWithAnsi(text, width);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
// JS fallback when native addon is unavailable (e.g., glibc mismatch on older Linux) (#1418)
|
|
97
|
+
const lines = [];
|
|
98
|
+
for (const line of text.split("\n")) {
|
|
99
|
+
if (line.length <= width) {
|
|
100
|
+
lines.push(line);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
// Simple word-wrap without ANSI awareness
|
|
104
|
+
let remaining = line;
|
|
105
|
+
while (remaining.length > width) {
|
|
106
|
+
const breakAt = remaining.lastIndexOf(" ", width);
|
|
107
|
+
const splitPoint = breakAt > 0 ? breakAt : width;
|
|
108
|
+
lines.push(remaining.slice(0, splitPoint));
|
|
109
|
+
remaining = remaining.slice(splitPoint).trimStart();
|
|
110
|
+
}
|
|
111
|
+
if (remaining)
|
|
112
|
+
lines.push(remaining);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return lines;
|
|
116
|
+
}
|
|
87
117
|
}
|
|
88
118
|
/**
|
|
89
119
|
* Map an ellipsis string to the native EllipsisKind enum value.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,YAAY,IAAI,kBAAkB,EAClC,gBAAgB,IAAI,sBAAsB,EAC1C,eAAe,IAAI,qBAAqB,EACxC,cAAc,IAAI,oBAAoB,EACtC,eAAe,IAAI,qBAAqB,EACxC,YAAY,GACZ,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AAClF,MAAM,UAAU,cAAc,CAC7B,IAAY,EACZ,QAAgB,EAChB,MAAc,EACd,MAAM,GAAG,KAAK;IAEd,OAAO,oBAAoB,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAC7D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC9B,IAAY,EACZ,SAAiB,EACjB,UAAkB,EAClB,QAAgB,EAChB,WAAW,GAAG,KAAK;IAEnB,OAAO,qBAAqB,CAAC,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;AAClF,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAY,EAAE,KAAa,EAAE,IAA8B;IAChG,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IACtC,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,GAAG,UAAU,CAAC,CAAC;IACtD,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IAE1C,MAAM,WAAW,GAAG,IAAI,GAAG,OAAO,CAAC;IACnC,OAAO,IAAI,CAAC,WAAW,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["import {\n\tvisibleWidth as nativeVisibleWidth,\n\twrapTextWithAnsi as nativeWrapTextWithAnsi,\n\ttruncateToWidth as nativeTruncateToWidth,\n\tsliceWithWidth as nativeSliceWithWidth,\n\textractSegments as nativeExtractSegments,\n\tEllipsisKind,\n} from \"@gsd/native/text\";\n\n// Grapheme segmenter (shared instance)\nconst segmenter = new Intl.Segmenter(undefined, { granularity: \"grapheme\" });\n\n/**\n * Get the shared grapheme segmenter instance.\n */\nexport function getSegmenter(): Intl.Segmenter {\n\treturn segmenter;\n}\n\nconst PUNCTUATION_REGEX = /[(){}[\\]<>.,;:'\"!?+\\-=*/\\\\|&%^$#@~`]/;\n\n/**\n * Check if a character is whitespace.\n */\nexport function isWhitespaceChar(char: string): boolean {\n\treturn /\\s/.test(char);\n}\n\n/**\n * Check if a character is punctuation.\n */\nexport function isPunctuationChar(char: string): boolean {\n\treturn PUNCTUATION_REGEX.test(char);\n}\n\n/**\n * Extract ANSI escape sequences from a string at the given position.\n */\nexport function extractAnsiCode(str: string, pos: number): { code: string; length: number } | null {\n\tif (pos >= str.length || str[pos] !== \"\\x1b\") return null;\n\n\tconst next = str[pos + 1];\n\n\t// CSI sequence: ESC [ ... m/G/K/H/J\n\tif (next === \"[\") {\n\t\tlet j = pos + 2;\n\t\twhile (j < str.length && !/[mGKHJ]/.test(str[j]!)) j++;\n\t\tif (j < str.length) return { code: str.substring(pos, j + 1), length: j + 1 - pos };\n\t\treturn null;\n\t}\n\n\t// OSC sequence: ESC ] ... BEL or ESC ] ... ST (ESC \\)\n\t// Used for hyperlinks (OSC 8), window titles, etc.\n\tif (next === \"]\") {\n\t\tlet j = pos + 2;\n\t\twhile (j < str.length) {\n\t\t\tif (str[j] === \"\\x07\") return { code: str.substring(pos, j + 1), length: j + 1 - pos };\n\t\t\tif (str[j] === \"\\x1b\" && str[j + 1] === \"\\\\\") return { code: str.substring(pos, j + 2), length: j + 2 - pos };\n\t\t\tj++;\n\t\t}\n\t\treturn null;\n\t}\n\n\t// APC sequence: ESC _ ... BEL or ESC _ ... ST (ESC \\)\n\t// Used for cursor marker and application-specific commands\n\tif (next === \"_\") {\n\t\tlet j = pos + 2;\n\t\twhile (j < str.length) {\n\t\t\tif (str[j] === \"\\x07\") return { code: str.substring(pos, j + 1), length: j + 1 - pos };\n\t\t\tif (str[j] === \"\\x1b\" && str[j + 1] === \"\\\\\") return { code: str.substring(pos, j + 2), length: j + 2 - pos };\n\t\t\tj++;\n\t\t}\n\t\treturn null;\n\t}\n\n\treturn null;\n}\n\n// ---------------------------------------------------------------------------\n// Native text module wrappers\n// ---------------------------------------------------------------------------\n\n/**\n * Calculate the visible width of a string in terminal columns.\n * Delegates to the native Rust implementation.\n */\nexport function visibleWidth(str: string): number {\n\treturn nativeVisibleWidth(str);\n}\n\n/**\n * Wrap text with ANSI codes preserved.\n * Delegates to the native Rust implementation.\n *\n * @param text - Text to wrap (may contain ANSI codes and newlines)\n * @param width - Maximum visible width per line\n * @returns Array of wrapped lines (NOT padded to width)\n */\nexport function wrapTextWithAnsi(text: string, width: number): string[] {\n\treturn nativeWrapTextWithAnsi(text, width);\n}\n\n/**\n * Map an ellipsis string to the native EllipsisKind enum value.\n */\nfunction ellipsisStringToKind(ellipsis: string): number {\n\tif (ellipsis === \"\\u2026\") return EllipsisKind.Unicode;\n\tif (ellipsis === \"...\" || ellipsis === undefined) return EllipsisKind.Ascii;\n\tif (ellipsis === \"\") return EllipsisKind.None;\n\t// Default: \"...\" maps to Ascii\n\treturn EllipsisKind.Ascii;\n}\n\n/**\n * Truncate text to fit within a maximum visible width, adding ellipsis if needed.\n * Optionally pad with spaces to reach exactly maxWidth.\n * Delegates to the native Rust implementation.\n *\n * @param text - Text to truncate (may contain ANSI codes)\n * @param maxWidth - Maximum visible width\n * @param ellipsis - Ellipsis string to append when truncating (default: \"...\")\n * @param pad - If true, pad result with spaces to exactly maxWidth (default: false)\n * @returns Truncated text, optionally padded to exactly maxWidth\n */\nexport function truncateToWidth(\n\ttext: string,\n\tmaxWidth: number,\n\tellipsis: string = \"...\",\n\tpad: boolean = false,\n): string {\n\treturn nativeTruncateToWidth(text, maxWidth, ellipsisStringToKind(ellipsis), pad);\n}\n\n/**\n * Extract a range of visible columns from a line. Handles ANSI codes and wide chars.\n * @param strict - If true, exclude wide chars at boundary that would extend past the range\n */\nexport function sliceByColumn(line: string, startCol: number, length: number, strict = false): string {\n\treturn sliceWithWidth(line, startCol, length, strict).text;\n}\n\n/** Like sliceByColumn but also returns the actual visible width of the result. */\nexport function sliceWithWidth(\n\tline: string,\n\tstartCol: number,\n\tlength: number,\n\tstrict = false,\n): { text: string; width: number } {\n\treturn nativeSliceWithWidth(line, startCol, length, strict);\n}\n\n/**\n * Extract \"before\" and \"after\" segments from a line in a single pass.\n * Delegates to the native Rust implementation.\n */\nexport function extractSegments(\n\tline: string,\n\tbeforeEnd: number,\n\tafterStart: number,\n\tafterLen: number,\n\tstrictAfter = false,\n): { before: string; beforeWidth: number; after: string; afterWidth: number } {\n\treturn nativeExtractSegments(line, beforeEnd, afterStart, afterLen, strictAfter);\n}\n\n/**\n * Apply background color to a line, padding to full width.\n *\n * @param line - Line of text (may contain ANSI codes)\n * @param width - Total width to pad to\n * @param bgFn - Background color function\n * @returns Line with background applied and padded to width\n */\nexport function applyBackgroundToLine(line: string, width: number, bgFn: (text: string) => string): string {\n\tconst visibleLen = visibleWidth(line);\n\tconst paddingNeeded = Math.max(0, width - visibleLen);\n\tconst padding = \" \".repeat(paddingNeeded);\n\n\tconst withPadding = line + padding;\n\treturn bgFn(withPadding);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,YAAY,IAAI,kBAAkB,EAClC,gBAAgB,IAAI,sBAAsB,EAC1C,eAAe,IAAI,qBAAqB,EACxC,cAAc,IAAI,oBAAoB,EACtC,eAAe,IAAI,qBAAqB,EACxC,YAAY,GACZ,MAAM,kBAAkB,CAAC;AAE1B,uCAAuC;AACvC,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC,CAAC;AAE7E;;GAEG;AACH,MAAM,UAAU,YAAY;IAC3B,OAAO,SAAS,CAAC;AAClB,CAAC;AAED,MAAM,iBAAiB,GAAG,sCAAsC,CAAC;AAEjE;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC5C,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACxB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC7C,OAAO,iBAAiB,CAAC,IA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AM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IAE1C,MAAM,WAAW,GAAG,IAAI,GAAG,OAAO,CAAC;IACnC,OAAO,IAAI,CAAC,WAAW,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["import {\n\tvisibleWidth as nativeVisibleWidth,\n\twrapTextWithAnsi as nativeWrapTextWithAnsi,\n\ttruncateToWidth as nativeTruncateToWidth,\n\tsliceWithWidth as nativeSliceWithWidth,\n\textractSegments as nativeExtractSegments,\n\tEllipsisKind,\n} from \"@gsd/native/text\";\n\n// Grapheme segmenter (shared instance)\nconst segmenter = new Intl.Segmenter(undefined, { granularity: \"grapheme\" });\n\n/**\n * Get the shared grapheme segmenter instance.\n */\nexport function getSegmenter(): Intl.Segmenter {\n\treturn segmenter;\n}\n\nconst PUNCTUATION_REGEX = /[(){}[\\]<>.,;:'\"!?+\\-=*/\\\\|&%^$#@~`]/;\n\n/**\n * Check if a character is whitespace.\n */\nexport function isWhitespaceChar(char: string): boolean {\n\treturn /\\s/.test(char);\n}\n\n/**\n * Check if a character is punctuation.\n */\nexport function isPunctuationChar(char: string): boolean {\n\treturn PUNCTUATION_REGEX.test(char);\n}\n\n/**\n * Extract ANSI escape sequences from a string at the given position.\n */\nexport function extractAnsiCode(str: string, pos: number): { code: string; length: number } | null {\n\tif (pos >= str.length || str[pos] !== \"\\x1b\") return null;\n\n\tconst next = str[pos + 1];\n\n\t// CSI sequence: ESC [ ... m/G/K/H/J\n\tif (next === \"[\") {\n\t\tlet j = pos + 2;\n\t\twhile (j < str.length && !/[mGKHJ]/.test(str[j]!)) j++;\n\t\tif (j < str.length) return { code: str.substring(pos, j + 1), length: j + 1 - pos };\n\t\treturn null;\n\t}\n\n\t// OSC sequence: ESC ] ... BEL or ESC ] ... ST (ESC \\)\n\t// Used for hyperlinks (OSC 8), window titles, etc.\n\tif (next === \"]\") {\n\t\tlet j = pos + 2;\n\t\twhile (j < str.length) {\n\t\t\tif (str[j] === \"\\x07\") return { code: str.substring(pos, j + 1), length: j + 1 - pos };\n\t\t\tif (str[j] === \"\\x1b\" && str[j + 1] === \"\\\\\") return { code: str.substring(pos, j + 2), length: j + 2 - pos };\n\t\t\tj++;\n\t\t}\n\t\treturn null;\n\t}\n\n\t// APC sequence: ESC _ ... BEL or ESC _ ... ST (ESC \\)\n\t// Used for cursor marker and application-specific commands\n\tif (next === \"_\") {\n\t\tlet j = pos + 2;\n\t\twhile (j < str.length) {\n\t\t\tif (str[j] === \"\\x07\") return { code: str.substring(pos, j + 1), length: j + 1 - pos };\n\t\t\tif (str[j] === \"\\x1b\" && str[j + 1] === \"\\\\\") return { code: str.substring(pos, j + 2), length: j + 2 - pos };\n\t\t\tj++;\n\t\t}\n\t\treturn null;\n\t}\n\n\treturn null;\n}\n\n// ---------------------------------------------------------------------------\n// Native text module wrappers\n// ---------------------------------------------------------------------------\n\n/**\n * Calculate the visible width of a string in terminal columns.\n * Delegates to the native Rust implementation.\n */\nexport function visibleWidth(str: string): number {\n\ttry {\n\t\treturn nativeVisibleWidth(str);\n\t} catch {\n\t\t// JS fallback — strip ANSI codes and return length (#1418)\n\t\treturn str.replace(/\\x1b\\[[0-9;]*m/g, \"\").length;\n\t}\n}\n\n/**\n * Wrap text with ANSI codes preserved.\n * Delegates to the native Rust implementation.\n *\n * @param text - Text to wrap (may contain ANSI codes and newlines)\n * @param width - Maximum visible width per line\n * @returns Array of wrapped lines (NOT padded to width)\n */\nexport function wrapTextWithAnsi(text: string, width: number): string[] {\n\ttry {\n\t\treturn nativeWrapTextWithAnsi(text, width);\n\t} catch {\n\t\t// JS fallback when native addon is unavailable (e.g., glibc mismatch on older Linux) (#1418)\n\t\tconst lines: string[] = [];\n\t\tfor (const line of text.split(\"\\n\")) {\n\t\t\tif (line.length <= width) {\n\t\t\t\tlines.push(line);\n\t\t\t} else {\n\t\t\t\t// Simple word-wrap without ANSI awareness\n\t\t\t\tlet remaining = line;\n\t\t\t\twhile (remaining.length > width) {\n\t\t\t\t\tconst breakAt = remaining.lastIndexOf(\" \", width);\n\t\t\t\t\tconst splitPoint = breakAt > 0 ? breakAt : width;\n\t\t\t\t\tlines.push(remaining.slice(0, splitPoint));\n\t\t\t\t\tremaining = remaining.slice(splitPoint).trimStart();\n\t\t\t\t}\n\t\t\t\tif (remaining) lines.push(remaining);\n\t\t\t}\n\t\t}\n\t\treturn lines;\n\t}\n}\n\n/**\n * Map an ellipsis string to the native EllipsisKind enum value.\n */\nfunction ellipsisStringToKind(ellipsis: string): number {\n\tif (ellipsis === \"\\u2026\") return EllipsisKind.Unicode;\n\tif (ellipsis === \"...\" || ellipsis === undefined) return EllipsisKind.Ascii;\n\tif (ellipsis === \"\") return EllipsisKind.None;\n\t// Default: \"...\" maps to Ascii\n\treturn EllipsisKind.Ascii;\n}\n\n/**\n * Truncate text to fit within a maximum visible width, adding ellipsis if needed.\n * Optionally pad with spaces to reach exactly maxWidth.\n * Delegates to the native Rust implementation.\n *\n * @param text - Text to truncate (may contain ANSI codes)\n * @param maxWidth - Maximum visible width\n * @param ellipsis - Ellipsis string to append when truncating (default: \"...\")\n * @param pad - If true, pad result with spaces to exactly maxWidth (default: false)\n * @returns Truncated text, optionally padded to exactly maxWidth\n */\nexport function truncateToWidth(\n\ttext: string,\n\tmaxWidth: number,\n\tellipsis: string = \"...\",\n\tpad: boolean = false,\n): string {\n\treturn nativeTruncateToWidth(text, maxWidth, ellipsisStringToKind(ellipsis), pad);\n}\n\n/**\n * Extract a range of visible columns from a line. Handles ANSI codes and wide chars.\n * @param strict - If true, exclude wide chars at boundary that would extend past the range\n */\nexport function sliceByColumn(line: string, startCol: number, length: number, strict = false): string {\n\treturn sliceWithWidth(line, startCol, length, strict).text;\n}\n\n/** Like sliceByColumn but also returns the actual visible width of the result. */\nexport function sliceWithWidth(\n\tline: string,\n\tstartCol: number,\n\tlength: number,\n\tstrict = false,\n): { text: string; width: number } {\n\treturn nativeSliceWithWidth(line, startCol, length, strict);\n}\n\n/**\n * Extract \"before\" and \"after\" segments from a line in a single pass.\n * Delegates to the native Rust implementation.\n */\nexport function extractSegments(\n\tline: string,\n\tbeforeEnd: number,\n\tafterStart: number,\n\tafterLen: number,\n\tstrictAfter = false,\n): { before: string; beforeWidth: number; after: string; afterWidth: number } {\n\treturn nativeExtractSegments(line, beforeEnd, afterStart, afterLen, strictAfter);\n}\n\n/**\n * Apply background color to a line, padding to full width.\n *\n * @param line - Line of text (may contain ANSI codes)\n * @param width - Total width to pad to\n * @param bgFn - Background color function\n * @returns Line with background applied and padded to width\n */\nexport function applyBackgroundToLine(line: string, width: number, bgFn: (text: string) => string): string {\n\tconst visibleLen = visibleWidth(line);\n\tconst paddingNeeded = Math.max(0, width - visibleLen);\n\tconst padding = \" \".repeat(paddingNeeded);\n\n\tconst withPadding = line + padding;\n\treturn bgFn(withPadding);\n}\n"]}
|
|
@@ -85,7 +85,12 @@ export function extractAnsiCode(str: string, pos: number): { code: string; lengt
|
|
|
85
85
|
* Delegates to the native Rust implementation.
|
|
86
86
|
*/
|
|
87
87
|
export function visibleWidth(str: string): number {
|
|
88
|
-
|
|
88
|
+
try {
|
|
89
|
+
return nativeVisibleWidth(str);
|
|
90
|
+
} catch {
|
|
91
|
+
// JS fallback — strip ANSI codes and return length (#1418)
|
|
92
|
+
return str.replace(/\x1b\[[0-9;]*m/g, "").length;
|
|
93
|
+
}
|
|
89
94
|
}
|
|
90
95
|
|
|
91
96
|
/**
|
|
@@ -97,7 +102,28 @@ export function visibleWidth(str: string): number {
|
|
|
97
102
|
* @returns Array of wrapped lines (NOT padded to width)
|
|
98
103
|
*/
|
|
99
104
|
export function wrapTextWithAnsi(text: string, width: number): string[] {
|
|
100
|
-
|
|
105
|
+
try {
|
|
106
|
+
return nativeWrapTextWithAnsi(text, width);
|
|
107
|
+
} catch {
|
|
108
|
+
// JS fallback when native addon is unavailable (e.g., glibc mismatch on older Linux) (#1418)
|
|
109
|
+
const lines: string[] = [];
|
|
110
|
+
for (const line of text.split("\n")) {
|
|
111
|
+
if (line.length <= width) {
|
|
112
|
+
lines.push(line);
|
|
113
|
+
} else {
|
|
114
|
+
// Simple word-wrap without ANSI awareness
|
|
115
|
+
let remaining = line;
|
|
116
|
+
while (remaining.length > width) {
|
|
117
|
+
const breakAt = remaining.lastIndexOf(" ", width);
|
|
118
|
+
const splitPoint = breakAt > 0 ? breakAt : width;
|
|
119
|
+
lines.push(remaining.slice(0, splitPoint));
|
|
120
|
+
remaining = remaining.slice(splitPoint).trimStart();
|
|
121
|
+
}
|
|
122
|
+
if (remaining) lines.push(remaining);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return lines;
|
|
126
|
+
}
|
|
101
127
|
}
|
|
102
128
|
|
|
103
129
|
/**
|
|
@@ -162,6 +162,77 @@ export function syncGsdStateToWorktree(mainBasePath: string, worktreePath_: stri
|
|
|
162
162
|
return { synced };
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
+
/**
|
|
166
|
+
* Sync milestone artifacts from worktree back to the main external state directory.
|
|
167
|
+
* Called before milestone merge to ensure completion artifacts (SUMMARY, VALIDATION,
|
|
168
|
+
* updated ROADMAP) are visible from the project root (#1412).
|
|
169
|
+
*
|
|
170
|
+
* Only syncs .gsd/milestones/ content — root-level files (DECISIONS, REQUIREMENTS, etc.)
|
|
171
|
+
* are handled by the merge itself.
|
|
172
|
+
*/
|
|
173
|
+
export function syncWorktreeStateBack(mainBasePath: string, worktreePath: string, milestoneId: string): { synced: string[] } {
|
|
174
|
+
const mainGsd = gsdRoot(mainBasePath);
|
|
175
|
+
const wtGsd = gsdRoot(worktreePath);
|
|
176
|
+
const synced: string[] = [];
|
|
177
|
+
|
|
178
|
+
// If both resolve to the same directory (symlink), no sync needed
|
|
179
|
+
try {
|
|
180
|
+
const mainResolved = realpathSync(mainGsd);
|
|
181
|
+
const wtResolved = realpathSync(wtGsd);
|
|
182
|
+
if (mainResolved === wtResolved) return { synced };
|
|
183
|
+
} catch {
|
|
184
|
+
// Can't resolve — proceed with sync
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const wtMilestoneDir = join(wtGsd, "milestones", milestoneId);
|
|
188
|
+
const mainMilestoneDir = join(mainGsd, "milestones", milestoneId);
|
|
189
|
+
|
|
190
|
+
if (!existsSync(wtMilestoneDir)) return { synced };
|
|
191
|
+
mkdirSync(mainMilestoneDir, { recursive: true });
|
|
192
|
+
|
|
193
|
+
// Sync milestone-level files (SUMMARY, VALIDATION, ROADMAP, CONTEXT)
|
|
194
|
+
try {
|
|
195
|
+
for (const entry of readdirSync(wtMilestoneDir, { withFileTypes: true })) {
|
|
196
|
+
if (entry.isFile() && entry.name.endsWith(".md")) {
|
|
197
|
+
const src = join(wtMilestoneDir, entry.name);
|
|
198
|
+
const dst = join(mainMilestoneDir, entry.name);
|
|
199
|
+
try {
|
|
200
|
+
cpSync(src, dst, { force: true });
|
|
201
|
+
synced.push(`milestones/${milestoneId}/${entry.name}`);
|
|
202
|
+
} catch { /* non-fatal */ }
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
} catch { /* non-fatal */ }
|
|
206
|
+
|
|
207
|
+
// Sync slice-level files (summaries, UATs)
|
|
208
|
+
const wtSlicesDir = join(wtMilestoneDir, "slices");
|
|
209
|
+
const mainSlicesDir = join(mainMilestoneDir, "slices");
|
|
210
|
+
if (existsSync(wtSlicesDir)) {
|
|
211
|
+
try {
|
|
212
|
+
for (const sliceEntry of readdirSync(wtSlicesDir, { withFileTypes: true })) {
|
|
213
|
+
if (!sliceEntry.isDirectory()) continue;
|
|
214
|
+
const sid = sliceEntry.name;
|
|
215
|
+
const wtSliceDir = join(wtSlicesDir, sid);
|
|
216
|
+
const mainSliceDir = join(mainSlicesDir, sid);
|
|
217
|
+
mkdirSync(mainSliceDir, { recursive: true });
|
|
218
|
+
|
|
219
|
+
for (const fileEntry of readdirSync(wtSliceDir, { withFileTypes: true })) {
|
|
220
|
+
if (fileEntry.isFile() && fileEntry.name.endsWith(".md")) {
|
|
221
|
+
const src = join(wtSliceDir, fileEntry.name);
|
|
222
|
+
const dst = join(mainSliceDir, fileEntry.name);
|
|
223
|
+
try {
|
|
224
|
+
cpSync(src, dst, { force: true });
|
|
225
|
+
synced.push(`milestones/${milestoneId}/slices/${sid}/${fileEntry.name}`);
|
|
226
|
+
} catch { /* non-fatal */ }
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
} catch { /* non-fatal */ }
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return { synced };
|
|
234
|
+
}
|
|
235
|
+
|
|
165
236
|
// ─── Worktree Post-Create Hook (#597) ────────────────────────────────────────
|
|
166
237
|
|
|
167
238
|
/**
|
|
@@ -131,6 +131,7 @@ import {
|
|
|
131
131
|
getAutoWorktreeOriginalBase,
|
|
132
132
|
mergeMilestoneToMain,
|
|
133
133
|
autoWorktreeBranch,
|
|
134
|
+
syncWorktreeStateBack,
|
|
134
135
|
} from "./auto-worktree.js";
|
|
135
136
|
import { pruneQueueOrder } from "./queue-order.js";
|
|
136
137
|
import { consumeSignal } from "./session-status-io.js";
|
|
@@ -377,6 +378,16 @@ function tryMergeMilestone(ctx: ExtensionContext, milestoneId: string, mode: "tr
|
|
|
377
378
|
// Worktree merge path
|
|
378
379
|
if (isInAutoWorktree(s.basePath) && s.originalBasePath) {
|
|
379
380
|
try {
|
|
381
|
+
// Sync completion artifacts from worktree → external state before merge (#1412)
|
|
382
|
+
try {
|
|
383
|
+
const { synced } = syncWorktreeStateBack(s.originalBasePath, s.basePath, milestoneId);
|
|
384
|
+
if (synced.length > 0) {
|
|
385
|
+
debugLog("worktree-reverse-sync", { milestoneId, synced: synced.length });
|
|
386
|
+
}
|
|
387
|
+
} catch (syncErr) {
|
|
388
|
+
debugLog("worktree-reverse-sync-failed", { milestoneId, error: getErrorMessage(syncErr) });
|
|
389
|
+
}
|
|
390
|
+
|
|
380
391
|
const roadmapPath = resolveMilestoneFile(s.originalBasePath, milestoneId, "ROADMAP");
|
|
381
392
|
if (!roadmapPath) {
|
|
382
393
|
teardownAutoWorktree(s.originalBasePath, milestoneId);
|
|
@@ -13,8 +13,8 @@ function run(command: string, cwd: string): string {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
async function main(): Promise<void> {
|
|
16
|
-
const base = mkdtempSync(join(tmpdir(), "gsd-repo-identity-"));
|
|
17
|
-
const stateDir = mkdtempSync(join(tmpdir(), "gsd-state-"));
|
|
16
|
+
const base = realpathSync(mkdtempSync(join(tmpdir(), "gsd-repo-identity-")));
|
|
17
|
+
const stateDir = realpathSync(mkdtempSync(join(tmpdir(), "gsd-state-")));
|
|
18
18
|
|
|
19
19
|
try {
|
|
20
20
|
process.env.GSD_STATE_DIR = stateDir;
|
|
@@ -38,7 +38,7 @@ async function main(): Promise<void> {
|
|
|
38
38
|
assertEq(worktreeState, expectedExternalState, "worktree symlink target matches main repo external state dir");
|
|
39
39
|
assertTrue(existsSync(join(worktreePath, ".gsd")), "worktree .gsd exists");
|
|
40
40
|
assertTrue(lstatSync(join(worktreePath, ".gsd")).isSymbolicLink(), "worktree .gsd is a symlink");
|
|
41
|
-
assertEq(realpathSync(join(worktreePath, ".gsd")), expectedExternalState, "worktree .gsd symlink resolves to main repo external state dir");
|
|
41
|
+
assertEq(realpathSync(join(worktreePath, ".gsd")), realpathSync(expectedExternalState), "worktree .gsd symlink resolves to main repo external state dir");
|
|
42
42
|
|
|
43
43
|
console.log("\n=== ensureGsdSymlink heals stale worktree symlinks ===");
|
|
44
44
|
const staleState = join(stateDir, "projects", "stale-worktree-state");
|
|
@@ -47,7 +47,7 @@ async function main(): Promise<void> {
|
|
|
47
47
|
symlinkSync(staleState, join(worktreePath, ".gsd"), "junction");
|
|
48
48
|
const healedState = ensureGsdSymlink(worktreePath);
|
|
49
49
|
assertEq(healedState, expectedExternalState, "stale worktree symlink is repaired to canonical external state dir");
|
|
50
|
-
assertEq(realpathSync(join(worktreePath, ".gsd")), expectedExternalState, "healed worktree symlink resolves to canonical external state dir");
|
|
50
|
+
assertEq(realpathSync(join(worktreePath, ".gsd")), realpathSync(expectedExternalState), "healed worktree symlink resolves to canonical external state dir");
|
|
51
51
|
|
|
52
52
|
console.log("\n=== ensureGsdSymlink preserves worktree .gsd directories ===");
|
|
53
53
|
rmSync(join(worktreePath, ".gsd"), { recursive: true, force: true });
|