Skip to content

Commit b456848

Browse files
mitchdennyCopilot
andauthored
Use session working directory in loc-breakdown canvas (#17862)
* Use session working directory in loc-breakdown canvas Forked extension processes inherit a cwd of ~/.copilot, which is not a git repo. With no explicit cwd input, buildReport ran git commands there and /data returned HTTP 500, surfacing as a load error in the canvas UI. Prefer the runtime-supplied ctx.session.workingDirectory (the user's worktree/repo) over process.cwd() in both the open handler and the refresh action's fallback path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Address review nits on cwd fallback wording - Update inputSchema cwd description to reflect that the session working directory is the primary default, with process.cwd() as a last-resort fallback. - Soften the inline comment on the open handler: the issue is that the extension process cwd is not necessarily the target session repo, not that ~/.copilot is never a git repo. - Mirror the docs update in the README's optional-inputs section. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 202cbb4 commit b456848

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

.github/extensions/loc-breakdown/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ action the agent can invoke to recompute the report.
4040

4141
Optional inputs when opening the canvas:
4242

43-
- `cwd` — working directory inside a git repo (defaults to the agent's cwd)
43+
- `cwd` — working directory inside a git repo (defaults to the active session's working directory, falling back to the extension process cwd)
4444
- `base` — base ref to diff against (defaults to `origin/HEAD`)
4545
- `head` — head ref (defaults to `HEAD`)
4646

.github/extensions/loc-breakdown/extension.mjs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ await joinSession({
483483
inputSchema: {
484484
type: "object",
485485
properties: {
486-
cwd: { type: "string", description: "Working directory inside the target git repo. Defaults to the canvas process cwd." },
486+
cwd: { type: "string", description: "Working directory inside the target git repo. Defaults to the active session's working directory (the user's worktree/repo); falls back to the extension process cwd only if the runtime did not supply one." },
487487
base: { type: "string", description: "Base ref to diff against. Defaults to origin/HEAD." },
488488
head: { type: "string", description: "Head ref. Defaults to HEAD." },
489489
},
@@ -494,7 +494,9 @@ await joinSession({
494494
description: "Recompute the LOC breakdown by re-running git diff and return the latest report as JSON.",
495495
handler: async (ctx) => {
496496
const entry = servers.get(ctx.instanceId);
497-
const opts = entry ? entry.opts : { cwd: process.cwd() };
497+
// Fall back to the session working directory (the user's worktree/repo) before
498+
// process.cwd(), which for forked extensions is typically ~/.copilot and not a git repo.
499+
const opts = entry ? entry.opts : { cwd: ctx.session?.workingDirectory || process.cwd() };
498500
const report = await buildReport(opts);
499501
return {
500502
ok: true,
@@ -513,8 +515,13 @@ await joinSession({
513515
],
514516
open: async (ctx) => {
515517
const input = ctx.input || {};
518+
// Prefer the explicit input.cwd, then the session's working directory supplied by
519+
// the runtime (CanvasSessionContext.workingDirectory). process.cwd() is a last resort
520+
// because the extension process cwd is not necessarily the target session's repo —
521+
// for forked extensions it's typically ~/.copilot, which is the wrong repo for this
522+
// report even on the rare setups where it happens to be a git repo itself.
516523
const opts = {
517-
cwd: input.cwd || process.cwd(),
524+
cwd: input.cwd || ctx.session?.workingDirectory || process.cwd(),
518525
base: input.base,
519526
head: input.head,
520527
};

0 commit comments

Comments
 (0)