Skip to content

Commit 5875b95

Browse files
refactor(worker): drop sessionWorkingDirectory/enableConfigDiscovery/enableSkills options
These three knobs added new public API to PilotSwarmWorkerOptions (and WorkerDefaults) just to plumb Copilot SDK session-config fields the SDK already owns. Remove them and fall back to the GHCP SDK defaults instead: - workingDirectory: per-session value only; otherwise the CLI uses process.cwd() (SDK default). The serve harness roots discovery by chdir-ing the worker process into the enlistment checkout (BUILD_SOURCESDIRECTORY / PILOTSWARM_SESSION_WORKING_DIR, guarded by a .github probe) — no SDK option. - enableConfigDiscovery / enableSkills: no override; sessions use SDK defaults (discovery off, skills on). Observability is kept: the per-session "GHCP-SDK createSession params" diagnostic still logs the effective workingDirectory / enableConfigDiscovery / enableSkills and the .github on-disk probes, and the worker-startup log states the SDK defaults in effect. Type-check + node --check pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 26f310eb-4680-4102-a8aa-f8d041940ab4
1 parent ad9d097 commit 5875b95

4 files changed

Lines changed: 40 additions & 76 deletions

File tree

packages/sdk/examples/session-worker.mjs

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
* Substrate-agnostic: it talks only to the durable store and calls no
1212
* ADO/CI APIs. ADO is merely the current invoker — the one ADO-flavored input
1313
* is the optional BUILD_SOURCESDIRECTORY checkout dir (with the generic
14-
* PILOTSWARM_SESSION_WORKING_DIR override) used to root the session so the
15-
* Copilot CLI can discover the enlistment's `.github` skills/agents.
14+
* PILOTSWARM_SESSION_WORKING_DIR override). When it points at a checkout that
15+
* contains `.github`, the harness chdir's into it so the Copilot CLI's default
16+
* workingDirectory (process.cwd()) roots there. Note: `.github` skill/agent
17+
* AUTO-discovery is a separate SDK knob (enableConfigDiscovery, default OFF)
18+
* that this harness does not force on — sessions use the GHCP SDK defaults.
1619
*
1720
* The turn is seeded OUT OF BAND by the customer client (the local portal's
1821
* REST API). This process only provides the worker (the compute that claims
@@ -99,13 +102,20 @@ try {
99102
const workerNodeId = process.env.WORKER_NODE_ID
100103
|| process.env.AGENT_NAME || process.env.POD_NAME || `${os.hostname()}#${process.pid}`;
101104

102-
// Platform-owned session working directory: when the ADO agent checked out
103-
// the enlistment (`checkout: self`), root every served session at that
104-
// checkout so the Copilot CLI discovers the repo's `.github`
105-
// skills/agents/instructions. The CUSTOMER never sets this — the platform
106-
// derives it from the agent's checkout (BUILD_SOURCESDIRECTORY), or an
107-
// explicit PILOTSWARM_SESSION_WORKING_DIR override. Guarded by an on-disk
108-
// `.github` probe so an empty (`checkout: none`) sources dir is ignored.
105+
// Root the served sessions at the enlistment checkout WITHOUT any custom
106+
// worker option: the Copilot SDK's default workingDirectory is the worker
107+
// process cwd, so we simply chdir into the checkout. When the ADO agent
108+
// checked out the enlistment (`checkout: self`), this lets the CLI's own
109+
// discovery resolve against the repo. The CUSTOMER never sets this — the
110+
// platform derives it from the agent's checkout (BUILD_SOURCESDIRECTORY),
111+
// or an explicit PILOTSWARM_SESSION_WORKING_DIR override. Guarded by an
112+
// on-disk `.github` probe so an empty (`checkout: none`) sources dir is
113+
// ignored.
114+
//
115+
// NOTE: `.github` skills/agents auto-discovery is a separate SDK knob
116+
// (enableConfigDiscovery, default OFF) that is NOT plumbed as a PilotSwarm
117+
// worker option — sessions fall back to the GHCP SDK defaults. Rooting cwd
118+
// here only affects the CLI's own working directory, not skill discovery.
109119
let sessionWorkingDirectory;
110120
const workDirCandidates = [
111121
process.env.PILOTSWARM_SESSION_WORKING_DIR,
@@ -116,17 +126,17 @@ try {
116126
if (fs.existsSync(path.join(cand, ".github"))) { sessionWorkingDirectory = cand; break; }
117127
} catch { /* ignore probe errors */ }
118128
}
119-
// Config discovery (the gate for `.github/skills` auto-discovery, SDK
120-
// default off) is turned on automatically whenever we rooted a checkout;
121-
// an explicit env can force it on without a detected checkout.
122-
const enableConfigDiscovery = sessionWorkingDirectory
123-
? true
124-
: truthy(process.env.PILOTSWARM_ENABLE_CONFIG_DISCOVERY);
125129
if (sessionWorkingDirectory) {
126-
console.log(`[session-worker] platform session workingDirectory=${sessionWorkingDirectory} (enableConfigDiscovery=${enableConfigDiscovery}) — repo .github skills/agents will be discovered`);
130+
try {
131+
process.chdir(sessionWorkingDirectory);
132+
console.log(`[session-worker] chdir -> ${sessionWorkingDirectory} (enlistment checkout with .github); Copilot CLI workingDirectory falls back to this cwd`);
133+
} catch (err) {
134+
console.log(`[session-worker] failed to chdir to ${sessionWorkingDirectory}: ${err?.message ?? err}; sessions use the current cwd (${process.cwd()})`);
135+
}
127136
} else {
128-
console.log(`[session-worker] no enlistment checkout detected (PILOTSWARM_SESSION_WORKING_DIR / BUILD_SOURCESDIRECTORY lacked .github); sessions use the worker cwd — repo .github skills NOT discovered (enableConfigDiscovery=${enableConfigDiscovery})`);
137+
console.log(`[session-worker] no enlistment checkout detected (PILOTSWARM_SESSION_WORKING_DIR / BUILD_SOURCESDIRECTORY lacked .github); sessions use the worker cwd (${process.cwd()})`);
129138
}
139+
console.log(`[session-worker] .github auto-discovery uses the GHCP SDK default (enableConfigDiscovery OFF) — repo .github skills are NOT auto-enumerated by this harness`);
130140

131141
const { PilotSwarmWorker, PilotSwarmManagementClient } = await import("pilotswarm-sdk");
132142

@@ -137,8 +147,6 @@ try {
137147
traceWriter: (m) => console.log(m),
138148
useManagedIdentity,
139149
aadDbUser,
140-
sessionWorkingDirectory,
141-
enableConfigDiscovery,
142150
blobAccountUrl: process.env.AZURE_STORAGE_ACCOUNT_URL || undefined,
143151
blobConnectionString: process.env.AZURE_STORAGE_CONNECTION_STRING || undefined,
144152
blobContainer: process.env.AZURE_STORAGE_CONTAINER || undefined,

packages/sdk/src/session-manager.ts

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,6 @@ export interface WorkerDefaults {
105105
appDefaultDescriptor?: import("./prompt-layers.js").PromptLayerDescriptor;
106106
/** Skill directories to pass to the Copilot SDK. */
107107
skillDirectories?: string[];
108-
/**
109-
* Default session workingDirectory (platform-owned). Applied only when the
110-
* per-session config does not specify one. Maps to the SDK session-config
111-
* `workingDirectory`; roots the CLI's `.github` config discovery.
112-
*/
113-
sessionWorkingDirectory?: string;
114-
/**
115-
* Enable the SDK's config discovery (skill dirs + MCP servers from the
116-
* session `workingDirectory`) for every session. SDK default is false.
117-
*/
118-
enableConfigDiscovery?: boolean;
119-
/** Explicit override for the SDK session-config `enableSkills`. */
120-
enableSkills?: boolean;
121108
/** Custom agents to pass to the Copilot SDK. */
122109
customAgents?: Array<{ name: string; description?: string; prompt: string; tools?: string[] | null; skills?: string[]; mcpServers?: Record<string, any> }>;
123110
/**
@@ -1301,11 +1288,12 @@ export class SessionManager {
13011288
// state placement (verified against @github/copilot 1.0.36). State location is
13021289
// controlled exclusively via COPILOT_HOME, set on the spawned CLI in ensureClient().
13031290
//
1304-
// workingDirectory: prefer the per-session value; otherwise fall back
1305-
// to the platform-owned default (e.g. the ADO agent's enlistment
1306-
// checkout). This is what roots the CLI's `.github` config discovery
1307-
// — the customer never has to know the agent's checkout path.
1308-
workingDirectory: config.workingDirectory ?? this.workerDefaults.sessionWorkingDirectory,
1291+
// workingDirectory: the per-session value when supplied; otherwise
1292+
// left unset so the Copilot CLI falls back to its own default
1293+
// (process.cwd()). The serve harness roots discovery by chdir-ing
1294+
// the worker process into the enlistment checkout — no PilotSwarm
1295+
// option required.
1296+
workingDirectory: config.workingDirectory,
13091297
hooks: config.hooks,
13101298
onPermissionRequest: (config as any).onPermissionRequest ?? approvePermissionForSession,
13111299
infiniteSessions: { enabled: true },
@@ -1330,12 +1318,6 @@ export class SessionManager {
13301318
// are the bound agent's own resolved map (see above).
13311319
...(this.workerDefaults.skillDirectories?.length && { skillDirectories: this.workerDefaults.skillDirectories }),
13321320
...(this.workerDefaults.customAgents?.length && { customAgents: this.workerDefaults.customAgents }),
1333-
// Platform-owned discovery knobs: when set, gate the CLI's
1334-
// auto-discovery of an enlistment's `.github` skills/MCP servers
1335-
// (rooted at workingDirectory). Only spread when explicitly set so
1336-
// sessions without a checkout keep the SDK defaults.
1337-
...(this.workerDefaults.enableConfigDiscovery != null && { enableConfigDiscovery: this.workerDefaults.enableConfigDiscovery }),
1338-
...(this.workerDefaults.enableSkills != null && { enableSkills: this.workerDefaults.enableSkills }),
13391321
...(Object.keys(effectiveMcpServers).length > 0 && { mcpServers: effectiveMcpServers }),
13401322
};
13411323

packages/sdk/src/types.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -947,33 +947,6 @@ export interface PilotSwarmWorkerOptions {
947947
*/
948948
skillDirectories?: string[];
949949

950-
/**
951-
* Default working directory applied to every session this worker serves,
952-
* used ONLY when the session's own config does not specify one. The
953-
* platform (never the customer) owns this: e.g. the ADO serve harness
954-
* points it at the agent's enlistment checkout so the Copilot CLI can
955-
* discover the repo's `.github` skills/agents/instructions. Maps to the
956-
* SDK session-config `workingDirectory`.
957-
*/
958-
sessionWorkingDirectory?: string;
959-
960-
/**
961-
* When true, enables the Copilot SDK's config discovery for every session
962-
* (auto-discovers skill directories + MCP servers from the session's
963-
* `workingDirectory`, e.g. an enlistment's `.github/skills`). SDK default
964-
* is false; PilotSwarm's own bundled skills load via `skillDirectories`
965-
* regardless of this flag. Set by the platform when it roots sessions at a
966-
* checkout. Maps to the SDK session-config `enableConfigDiscovery`.
967-
*/
968-
enableConfigDiscovery?: boolean;
969-
970-
/**
971-
* Explicit override for the SDK session-config `enableSkills`. Leave unset
972-
* to keep the SDK default (skills on). When false, NO skills load at all
973-
* (including `skillDirectories`).
974-
*/
975-
enableSkills?: boolean;
976-
977950
/**
978951
* Additional custom agents (beyond plugins).
979952
* Passed directly to the SDK's `customAgents` config.

packages/sdk/src/worker.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,6 @@ export class PilotSwarmWorker {
300300
appDefaultDescriptor: this._appDefaultDescriptor ?? undefined,
301301
skillDirectories: this._loadedSkillDirs,
302302
customAgents: this._loadedAgents,
303-
sessionWorkingDirectory: options.sessionWorkingDirectory,
304-
enableConfigDiscovery: options.enableConfigDiscovery,
305-
enableSkills: options.enableSkills,
306303
mcpServers: this._loadedMcpServers,
307304
agentMcpServers: this._agentMcpServers,
308305
baseMcpServers: this._baseMcpServers,
@@ -342,9 +339,13 @@ export class PilotSwarmWorker {
342339
customAgentCount: this._loadedAgents.length,
343340
customAgentNames: this._loadedAgents.map((a) => a.name),
344341
mcpServerNames: Object.keys(this._loadedMcpServers),
345-
sessionWorkingDirectory: this.config.sessionWorkingDirectory ?? "(unset -> sessions use their own cwd)",
346-
enableConfigDiscovery: this.config.enableConfigDiscovery ?? "(unset -> SDK default false)",
347-
enableSkills: this.config.enableSkills ?? "(unset -> SDK default on)",
342+
// These three are not worker-owned options: sessions inherit
343+
// the Copilot SDK defaults. workingDirectory falls back to the
344+
// worker process cwd (chdir the process to root discovery),
345+
// enableConfigDiscovery defaults off, enableSkills defaults on.
346+
sessionWorkingDirectory: "(SDK default -> process.cwd())",
347+
enableConfigDiscovery: "(SDK default -> false)",
348+
enableSkills: "(SDK default -> on)",
348349
defaultModel: this._modelProviders?.defaultModel ?? "(unset)",
349350
modelCatalogCount: this._modelProviders?.allModels.length ?? 0,
350351
}),

0 commit comments

Comments
 (0)