fix(data): normalize a list working dir's trailing separator on write

A list working_dir stored as "C:\Dev\Tests\StaplerTracking\" broke every consumer
that puts it on a Windows command line: argv rules read \" as an escaped quote, so
the token never closes. "Open in terminal" passed wt.exe a starting directory of
C:\Dev\Tests\StaplerTracking" and it failed with 0x8007010b; the same data had
already corrupted the ConPTY list handler's arg list in August.

Paths.TrimTrailingSeparator is now the single helper (replacing the copies in
InteractiveLaunchSpecService and ClaudeHelpLauncher) and ListRepository applies it
on Add/Update, which covers every writer: UI create, repo import, hub UpdateList,
and MCP CreateList/UpdateList. OpenInTerminal also switches to ArgumentList so its
quoting is correct regardless of what's stored.
This commit is contained in:
mika kuns
2026-08-10 17:12:46 +02:00
parent 6d8cbacc9b
commit d451edd367
7 changed files with 150 additions and 18 deletions
+16
View File
@@ -25,6 +25,22 @@ public static class Paths
return Path.GetFullPath(expanded);
}
/// <summary>
/// Strips trailing directory separators off a path bound for a Windows command line. Windows
/// argv rules read <c>\"</c> as an escaped quote, so a quoted token ending in '\' never closes
/// (<c>"C:\repo\"</c> parses as <c>C:\repo"</c>) and either the path itself or every argument
/// after it is corrupted. A bare root ("C:\", "/") is all separator and is returned untouched;
/// so is null/blank.
/// </summary>
public static string? TrimTrailingSeparator(string? path)
{
if (string.IsNullOrWhiteSpace(path))
return path;
var trimmed = path.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
return trimmed.Length == 0 || trimmed.EndsWith(':') ? path : trimmed;
}
/// <summary>~/.todo-app — parent directory for db, logs, config, sandbox, worktrees.</summary>
public static string AppDataRoot() =>
Expand("~/.todo-app");
@@ -16,16 +16,25 @@ public sealed class ListRepository
public async Task AddAsync(ListEntity entity, CancellationToken ct = default)
{
NormalizeWorkingDir(entity);
_context.Lists.Add(entity);
await _context.SaveChangesAsync(ct);
}
public async Task UpdateAsync(ListEntity entity, CancellationToken ct = default)
{
NormalizeWorkingDir(entity);
_context.Lists.Update(entity);
await _context.SaveChangesAsync(ct);
}
// A working dir is user-supplied (typed, folder-picked, imported, or set over MCP) and every
// consumer eventually hands it to the claude CLI or wt.exe as one quoted command-line token —
// where a trailing '\' escapes its own closing quote. Normalizing here covers all writers;
// see Paths.TrimTrailingSeparator.
private static void NormalizeWorkingDir(ListEntity entity) =>
entity.WorkingDir = Paths.TrimTrailingSeparator(entity.WorkingDir);
public async Task DeleteAsync(string listId, CancellationToken ct = default)
{
var taskIds = await _context.Tasks
@@ -178,5 +178,6 @@ public sealed class ClaudeHelpLauncher
private static string Quote(string value) => value.Contains(' ') ? $"\"{value}\"" : value;
private static string QuoteDirectory(string directory) => Quote(directory.TrimEnd('\\', '/'));
private static string QuoteDirectory(string directory) =>
Quote(ClaudeDo.Data.Paths.TrimTrailingSeparator(directory)!);
}
@@ -143,15 +143,21 @@ public sealed partial class ListsIslandViewModel : ViewModelBase, IDisposable
{
var dir = row?.WorkingDir;
if (string.IsNullOrWhiteSpace(dir) || !System.IO.Directory.Exists(dir)) return;
// Trailing separator + ArgumentList, not string interpolation: "C:\repo\" would parse as
// C:\repo" and wt would refuse it as a starting directory (Paths.TrimTrailingSeparator).
// Rows loaded before ListRepository normalized on write can still carry one.
dir = Paths.TrimTrailingSeparator(dir)!;
ForegroundHelper.AllowAny();
try
{
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
var psi = new System.Diagnostics.ProcessStartInfo
{
FileName = "wt.exe",
Arguments = $"-d \"{dir}\"",
UseShellExecute = true,
});
};
psi.ArgumentList.Add("-d");
psi.ArgumentList.Add(dir);
System.Diagnostics.Process.Start(psi);
}
catch
{
@@ -352,18 +352,12 @@ public sealed class InteractiveLaunchSpecService : IInteractiveLaunchSpecService
return new LaunchSpec(repoDir, resolvedClaude, args, env);
}
// Strips a trailing directory separator off a path bound for the CLI argument list. The ConPTY
// host flattens Args into ONE Windows command line and quotes each token, so a token ending in
// '\' escapes its own closing quote ("C:\repo\" parses as C:\repo" ...) and every following
// argument is absorbed into the preceding variadic flag -- for a list handler that means
// --add-dir swallows --append-system-prompt-file AND the positional kickoff, and the session
// opens with no prompt at all. Only user-supplied list working dirs can carry one; the session
// dirs we build never do. A bare root ("C:\", "/") is all separator and is left untouched.
private static string TrimTrailingSeparator(string dir)
{
var trimmed = dir.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
return trimmed.Length == 0 || trimmed.EndsWith(':') ? dir : trimmed;
}
// The ConPTY host flattens Args into ONE Windows command line and quotes each token, so a token
// ending in '\' escapes its own closing quote and every following argument is absorbed into the
// preceding variadic flag -- for a list handler that means --add-dir swallows
// --append-system-prompt-file AND the positional kickoff, and the session opens with no prompt
// at all. ListRepository normalizes on write now, but rows written before that still carry one.
private static string TrimTrailingSeparator(string dir) => Paths.TrimTrailingSeparator(dir)!;
// Renders one task as a brief list item. A description can itself be arbitrary Markdown
// (headings, lists, fenced code) — those must not merge into the brief's own task list, so