Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix(cline-plugin): read the workspace from a nested setup context

Claudeaa17d536f1ad
diff --git a/cli/beacon/internal/endpoint/hooks/assets/cline/beacon.ts b/cli/beacon/internal/endpoint/hooks/assets/cline/beacon.ts
index baf151b3..1c5dea0d 100644
--- a/cli/beacon/internal/endpoint/hooks/assets/cline/beacon.ts
+++ b/cli/beacon/internal/endpoint/hooks/assets/cline/beacon.ts
@@ -154,15 +154,39 @@ async function sendToBeacon(payload: Record<string, unknown>): Promise<void> {
// handler's context puts them, so several shapes are tried and a miss costs the field rather than
// the event. The hook adapter reads the same names, so anything missed here is still recoverable
// from the forwarded context.
+function asRecord(value: unknown): Record<string, unknown> {
+ return value !== null && typeof value === "object" && !Array.isArray(value)
+ ? (value as Record<string, unknown>)
+ : {}
+}
+
function identity(context: Record<string, unknown> | undefined): Record<string, unknown> {
if (!context) return {}
- const task = (context.task ?? context.run ?? {}) as Record<string, unknown>
+ const task = asRecord(context.task ?? context.run)
+ // The setup context is reported to carry the workspace under an object of its own rather than at
+ // the top level. Read in addition to the top level, not instead of it: the two hook surfaces do
+ // not agree on shape, and this is the only place the workspace is guaranteed to appear at all --
+ // a miss here costs the working directory, the repository and the branch on every event of the
+ // task, which is what makes it worth reading more than one spelling.
+ const workspace = asRecord(context.workspaceInfo ?? context.workspace_info ?? context.workspace)
const fields: Record<string, unknown> = {}
const taskId = context.taskId ?? context.taskID ?? context.task_id ?? task.id ?? task.taskId
if (taskId) fields.taskId = taskId
- const roots = context.workspaceRoots ?? context.workspace_roots ?? context.workspaceFolders
+ const roots =
+ context.workspaceRoots ??
+ context.workspace_roots ??
+ context.workspaceFolders ??
+ workspace.workspaceRoots ??
+ workspace.roots
if (roots) fields.workspaceRoots = roots
- const cwd = context.cwd ?? context.workingDirectory ?? context.working_directory
+ const cwd =
+ context.cwd ??
+ context.workingDirectory ??
+ context.working_directory ??
+ workspace.rootPath ??
+ workspace.root_path ??
+ workspace.cwd ??
+ workspace.path
if (cwd) fields.cwd = cwd
const version = context.clineVersion ?? context.cline_version ?? context.version
if (version) fields.clineVersion = version
diff --git a/plugins/cline-beacon/src/beacon.test.ts b/plugins/cline-beacon/src/beacon.test.ts
index 41832684..24ae8e37 100644
--- a/plugins/cline-beacon/src/beacon.test.ts
+++ b/plugins/cline-beacon/src/beacon.test.ts
@@ -62,6 +62,41 @@ describe("beacon cline plugin", () => {
expect(sent[0].clineVersion).toBe("3.36.0")
})
+ // The shape above is a top-level one. The setup context is reported to nest the workspace under
+ // an object of its own, and reading only the top level extracted nothing to carry -- costing the
+ // working directory, repository and branch on every event of the task.
+ test("carries a nested setup workspace onto later hooks", async () => {
+ const sent = captureSends()
+ const plugin = createBeaconPlugin()
+
+ plugin.setup(undefined, { workspaceInfo: { rootPath: "/repo" }, clineVersion: "3.36.0" })
+ await plugin.hooks.afterTool({ toolCall: { name: "read_file" } })
+
+ expect(sent[0].cwd).toBe("/repo")
+ expect(sent[0].clineVersion).toBe("3.36.0")
+ })
+
+ test("reads a nested roots array", async () => {
+ const sent = captureSends()
+ const plugin = createBeaconPlugin()
+
+ plugin.setup(undefined, { workspace: { roots: ["/repo", "/other"] } })
+ await plugin.hooks.beforeRun({ taskId: "task-1" })
+
+ expect(sent[0].workspaceRoots).toEqual(["/repo", "/other"])
+ })
+
+ // A non-object under a workspace key must not throw: the plugin runs inside the host, and an
+ // exception here reaches the user as a broken plugin.
+ test("survives a non-object workspace value", async () => {
+ const sent = captureSends()
+ const plugin = createBeaconPlugin()
+
+ plugin.setup(undefined, { workspaceInfo: "/repo" })
+ await expect(plugin.hooks.beforeRun({ taskId: "task-1" })).resolves.toBeUndefined()
+ expect(sent[0].taskId).toBe("task-1")
+ })
+
test("context fields win over the captured setup context", async () => {
const sent = captureSends()
const plugin = createBeaconPlugin()
diff --git a/plugins/cline-beacon/src/beacon.ts b/plugins/cline-beacon/src/beacon.ts
index baf151b3..1c5dea0d 100644
--- a/plugins/cline-beacon/src/beacon.ts
+++ b/plugins/cline-beacon/src/beacon.ts
@@ -154,15 +154,39 @@ async function sendToBeacon(payload: Record<string, unknown>): Promise<void> {
// handler's context puts them, so several shapes are tried and a miss costs the field rather than
// the event. The hook adapter reads the same names, so anything missed here is still recoverable
// from the forwarded context.
+function asRecord(value: unknown): Record<string, unknown> {
+ return value !== null && typeof value === "object" && !Array.isArray(value)
+ ? (value as Record<string, unknown>)
+ : {}
+}
+
function identity(context: Record<string, unknown> | undefined): Record<string, unknown> {
if (!context) return {}
- const task = (context.task ?? context.run ?? {}) as Record<string, unknown>
+ const task = asRecord(context.task ?? context.run)
+ // The setup context is reported to carry the workspace under an object of its own rather than at
+ // the top level. Read in addition to the top level, not instead of it: the two hook surfaces do
+ // not agree on shape, and this is the only place the workspace is guaranteed to appear at all --
+ // a miss here costs the working directory, the repository and the branch on every event of the
+ // task, which is what makes it worth reading more than one spelling.
+ const workspace = asRecord(context.workspaceInfo ?? context.workspace_info ?? context.workspace)
const fields: Record<string, unknown> = {}
const taskId = context.taskId ?? context.taskID ?? context.task_id ?? task.id ?? task.taskId
if (taskId) fields.taskId = taskId
- const roots = context.workspaceRoots ?? context.workspace_roots ?? context.workspaceFolders
+ const roots =
+ context.workspaceRoots ??
+ context.workspace_roots ??
+ context.workspaceFolders ??
+ workspace.workspaceRoots ??
+ workspace.roots
if (roots) fields.workspaceRoots = roots
- const cwd = context.cwd ?? context.workingDirectory ?? context.working_directory
+ const cwd =
+ context.cwd ??
+ context.workingDirectory ??
+ context.working_directory ??
+ workspace.rootPath ??
+ workspace.root_path ??
+ workspace.cwd ??
+ workspace.path
if (cwd) fields.cwd = cwd
const version = context.clineVersion ?? context.cline_version ?? context.version
if (version) fields.clineVersion = version