@cirtium/acent-connect 1.2.1 → 1.2.2

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "acent",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Recall past work, trace code changes, revisit decisions, and resume tasks with Acent.",
5
5
  "mcpServers": "./mcp-claude.json",
6
6
  "hooks": "./hooks/claude.json"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "acent",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Recall past work, trace code changes, revisit decisions, and resume tasks with Acent.",
5
5
  "skills": "./skills/",
6
6
  "mcpServers": "./mcp-codex.json",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "acent",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Recall past work, trace code changes, revisit decisions, and resume tasks with Acent.",
5
5
  "author": {
6
6
  "name": "Cirtium"
@@ -1,7 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
  import { spawn } from "node:child_process"
3
3
  import { fileURLToPath } from "node:url"
4
+ import { recordWorkspaceCall, workspaceInstructions } from "./antigravity-workspace.mjs"
4
5
  const started = Date.now()
6
+ const event = process.argv[2]
7
+ let output = event === "PreToolUse" ? { decision: "allow" } : {}
5
8
  try {
6
9
  let raw = ""
7
10
  for await (const chunk of process.stdin) {
@@ -9,8 +12,12 @@ try {
9
12
  if (Buffer.byteLength(raw) > 2 * 1024 * 1024) throw new Error("Hook event exceeds 2 MiB.")
10
13
  }
11
14
  const payload = JSON.parse(raw)
12
- payload.acent_hook = process.argv[2]
15
+ payload.acent_hook = event
13
16
  if (!["PreInvocation", "PostInvocation", "Stop", "PreToolUse", "PostToolUse"].includes(payload.acent_hook)) throw new Error("Unknown Antigravity hook.")
17
+ if (event === "PreInvocation") output = workspaceInstructions(payload)
18
+ if (event === "PreToolUse") {
19
+ await recordWorkspaceCall(payload).catch(() => console.error("Acent could not verify this workspace call."))
20
+ }
14
21
  await new Promise((resolve, reject) => {
15
22
  const child = spawn(process.execPath, [fileURLToPath(new URL("./hook.mjs", import.meta.url)), "--tool", "Antigravity"],
16
23
  { stdio: ["pipe", "ignore", "inherit"] })
@@ -21,5 +28,5 @@ try {
21
28
  })
22
29
  console.error("Acent capture timing: " + JSON.stringify({at:new Date().toISOString(),stage:"finished",durationMs:Date.now()-started}))
23
30
  } catch (error) { console.error("Acent could not save this event.") }
24
- // Hooks must emit a JSON object and must never force the agent to continue.
25
- process.stdout.write("{}\n")
31
+ // PreToolUse delegates the decision to Antigravity's normal permission policy.
32
+ process.stdout.write(JSON.stringify(output) + "\n")
@@ -0,0 +1,92 @@
1
+ import { createHash, randomUUID } from "node:crypto"
2
+ import { mkdir, readFile, readdir, realpath, rename, stat, unlink, writeFile } from "node:fs/promises"
3
+ import { homedir } from "node:os"
4
+ import { join } from "node:path"
5
+ import { projectFolder } from "./connection-context.mjs"
6
+
7
+ const lifetimeMs = 60_000
8
+ const toolName = "acent_workspace"
9
+ const serverName = "acent_acent"
10
+ const isConversationId = value => typeof value === "string" && /^[a-zA-Z0-9_-]{1,128}$/.test(value)
11
+
12
+ export const antigravityWorkspaceTool = {
13
+ name: toolName,
14
+ description: "Use Acent in the current Antigravity chat when the regular Acent tools cannot identify its workspace. Use the conversation ID supplied by the Acent hook. Omit tool to list the available tools, or set tool to acent_connect or an Acent tool from the returned list.",
15
+ inputSchema: {
16
+ type: "object",
17
+ properties: {
18
+ conversationId: { type: "string", description: "Conversation ID supplied by the Acent hook in this chat." },
19
+ tool: { type: "string", description: "Acent tool to call. Omit to list tools." },
20
+ arguments: { type: "object", description: "Arguments for the selected Acent tool." },
21
+ },
22
+ required: ["conversationId"],
23
+ additionalProperties: false,
24
+ },
25
+ }
26
+
27
+ function ordered(value) {
28
+ if (Array.isArray(value)) return value.map(ordered)
29
+ if (!value || typeof value !== "object") return value
30
+ return Object.fromEntries(Object.keys(value).sort().map(key => [key, ordered(value[key])]))
31
+ }
32
+
33
+ function evidenceFile(args) {
34
+ const dir = join(process.env.ACENT_CONFIG_HOME || join(homedir(), ".config", "acent"), "antigravity-workspaces")
35
+ const key = createHash("sha256").update(JSON.stringify(ordered(args))).digest("hex")
36
+ return { dir, file: join(dir, `${key}.json`) }
37
+ }
38
+
39
+ export function workspaceInstructions(payload) {
40
+ if (payload.invocationNum !== 0 || !isConversationId(payload.conversationId)) return {}
41
+ return { injectSteps: [{ systemMessage: { systemMessage:
42
+ `When Acent tools are needed and the regular Acent server cannot identify this workspace, use ${toolName} on ${serverName} with conversationId ${payload.conversationId}. To connect, set tool to acent_connect. To use connected tools, omit tool to list them, then pass the chosen tool and its arguments to ${toolName}. Use only the conversation ID supplied by this hook.`
43
+ } }] }
44
+ }
45
+
46
+ export async function recordWorkspaceCall(payload) {
47
+ const call = payload.toolCall
48
+ const lazy = call?.name === "call_mcp_tool" && call.args?.ServerName === serverName && call.args?.ToolName === toolName
49
+ const eager = call?.name === `mcp_${serverName}_${toolName}`
50
+ if (!lazy && !eager) return
51
+ const args = lazy ? call.args.Arguments : call.args
52
+ if (!isConversationId(payload.conversationId) || args?.conversationId !== payload.conversationId) return
53
+
54
+ const roots = payload.workspacePaths
55
+ if (!Array.isArray(roots) || roots.length > 1) return
56
+ const folder = roots.length === 1 ? projectFolder(roots[0]) : undefined
57
+ if (roots.length === 1 && !folder) return
58
+ const context = folder ? { scope: "folder", folder: await realpath(folder) } : { scope: "general" }
59
+ const { dir, file } = evidenceFile(args)
60
+ await mkdir(dir, { recursive: true, mode: 0o700 })
61
+ const now = Date.now()
62
+ await Promise.all((await readdir(dir)).map(async entry => {
63
+ const path = join(dir, entry)
64
+ const info = await stat(path).catch(() => undefined)
65
+ if (info?.isFile() && now - info.mtimeMs > lifetimeMs) await unlink(path).catch(() => {})
66
+ }))
67
+ const temporary = `${file}.${randomUUID()}`
68
+ try {
69
+ await writeFile(temporary, JSON.stringify({ context, expires: now + lifetimeMs }), { mode: 0o600, flag: "wx" })
70
+ await rename(temporary, file)
71
+ } finally {
72
+ await unlink(temporary).catch(() => {})
73
+ }
74
+ }
75
+
76
+ export async function consumeWorkspaceCall(args) {
77
+ if (!isConversationId(args?.conversationId)) return undefined
78
+ const { file } = evidenceFile(args)
79
+ const claimed = `${file}.${randomUUID()}`
80
+ try {
81
+ await rename(file, claimed)
82
+ } catch (error) {
83
+ if (error.code === "ENOENT") return undefined
84
+ throw error
85
+ }
86
+ try {
87
+ const { context, expires } = JSON.parse(await readFile(claimed, "utf8"))
88
+ return expires >= Date.now() ? context : undefined
89
+ } finally {
90
+ await unlink(claimed).catch(() => {})
91
+ }
92
+ }
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { encryptedReadTool, readEncryptedRecords, privateGrant } from "./encrypted-capture.mjs"
3
- import { readFile } from "node:fs/promises"
3
+ import { readFile, realpath } from "node:fs/promises"
4
4
  import { connectionGuidance } from "./host-guidance.mjs"
5
5
  // Folder-scoped MCP with setup available even before the first authorization.
6
6
  import { clarificationInstructions, clarificationTool, clarify, createQuestionChannel } from "./clarification.mjs"
@@ -11,7 +11,9 @@ import { bridgeInstructions, bridgeTools, createBridge } from "./bridge.mjs"
11
11
  import { bridgeCaptureEvents } from "./bridge-capture.mjs"
12
12
  import { createInterface } from "node:readline"
13
13
  import { mkdir } from "node:fs/promises"
14
- import { dirname } from "node:path"
14
+ import { dirname, resolve } from "node:path"
15
+ import { fileURLToPath } from "node:url"
16
+ import { antigravityWorkspaceTool, consumeWorkspaceCall } from "./antigravity-workspace.mjs"
15
17
  import { createPluginUpdateNotice, pluginUpdateInstructions, readPluginInstallation } from "./plugin-updates.mjs"
16
18
  import {
17
19
  options,
@@ -30,6 +32,8 @@ const launchFolder = folderIndex < 0 ? undefined : launchArgs[folderIndex + 1]
30
32
  if (folderIndex >= 0 && !projectFolder(launchFolder)) launchArgs.splice(folderIndex, 2)
31
33
  const startupConfig = await boundConfig(["flush", ...launchArgs])
32
34
  let activeConfig = startupConfig
35
+ const isAntigravity = startupConfig.tool === "Antigravity"
36
+ const pluginFolder = resolve(fileURLToPath(new URL("..", import.meta.url)))
33
37
  const recoverCursorFolder = startupConfig.tool === "Cursor" &&
34
38
  launchFolder === "${workspaceFolder}" && !launchArgs.includes("--general")
35
39
  const installation = await readPluginInstallation(activeConfig.tool).catch(() => null)
@@ -38,6 +42,7 @@ let clientCapabilities = {}
38
42
  let protocol
39
43
  let pendingConnection
40
44
  let connectionUrl
45
+ let connectionDirectory
41
46
  const setupTool = {
42
47
  name: "acent_connect",
43
48
  title: "Acent Connect",
@@ -67,14 +72,26 @@ function recoverCursorConfig() {
67
72
  return cursorFolderRecovery
68
73
  }
69
74
 
70
- async function detectConnectionContext(config) {
75
+ async function detectConnectionContext(config, verifiedWorkspace) {
76
+ if (verifiedWorkspace) {
77
+ return { context: verifiedWorkspace, roots: verifiedWorkspace.folder ? undefined : [] }
78
+ }
71
79
  const roots = clientCapabilities.roots ? await rootRequests.request() : undefined
80
+ const explicitGeneral = config.general &&
81
+ (config !== startupConfig || launchArgs.includes("--general"))
82
+ const bound = isAntigravity && !projectFolder(launchFolder)
83
+ ? explicitGeneral ? { ...config, bindingKnown: true } : undefined
84
+ : config
72
85
  const context = connectionContext({
73
86
  roots,
74
87
  explicitFolder: projectFolder(launchFolder) ||
75
88
  (config.tool === "Cursor" ? process.env.CURSOR_PROJECT_DIR : undefined),
76
- bound: recoverCursorFolder && config === startupConfig ? undefined : config,
89
+ bound: recoverCursorFolder && config === startupConfig ? undefined : bound,
77
90
  })
91
+ if (isAntigravity && context.scope === "folder" &&
92
+ await realpath(context.folder).catch(() => resolve(context.folder)) === pluginFolder) {
93
+ return { context: { scope: "unknown" }, roots }
94
+ }
78
95
  return { context, roots }
79
96
  }
80
97
 
@@ -101,7 +118,8 @@ const needsConnection = (error) =>
101
118
  error.code === "invalid_grant" ||
102
119
  error.code === "project_unavailable" ||
103
120
  error.status === 401
104
- const setupTools = () => ({ tools: [setupTool, ...localBridgeTools] })
121
+ const workspaceTools = isAntigravity ? [antigravityWorkspaceTool] : []
122
+ const setupTools = () => ({ tools: [setupTool, ...localBridgeTools, ...workspaceTools] })
105
123
 
106
124
  function toolErrorMessage(error) {
107
125
  if (needsConnection(error))
@@ -137,13 +155,16 @@ async function postMcp(config, access, message) {
137
155
  }
138
156
  async function startConnection(config) {
139
157
  const directory = configDirectory(config)
140
- if (pendingConnection) return connectionUrl
141
- await mkdir(directory, { recursive: true, mode: 0o700 })
158
+ if (pendingConnection) {
159
+ if (directory !== connectionDirectory)
160
+ throw new Error("Finish the pending connection before changing its workspace")
161
+ return connectionUrl
162
+ }
163
+ connectionDirectory = directory
142
164
  const ready = Promise.withResolvers()
143
- pendingConnection = connect(config, directory, (url) => {
144
- connectionUrl = url.toString()
145
- ready.resolve(connectionUrl)
146
- })
165
+ pendingConnection = mkdir(directory, { recursive: true, mode: 0o700 }).then(() => connect(config, directory, (url) => {
166
+ ready.resolve(url.toString())
167
+ }))
147
168
  .then(() => {
148
169
  config.bindingKnown = true
149
170
  write({ jsonrpc: "2.0", method: "notifications/tools/list_changed" })
@@ -155,13 +176,16 @@ async function startConnection(config) {
155
176
  .finally(() => {
156
177
  pendingConnection = undefined
157
178
  connectionUrl = undefined
179
+ connectionDirectory = undefined
158
180
  })
159
- return ready.promise
181
+ connectionUrl = ready.promise
182
+ return connectionUrl
160
183
  }
161
184
  const lines = createInterface({ input: process.stdin, crlfDelay: Infinity })
162
185
  async function handleLine(line) {
163
186
  if (!line.trim()) return
164
187
  let message
188
+ let workspaceCatalog = false
165
189
  try {
166
190
  let config = activeConfig
167
191
  if (Buffer.byteLength(line) > 64 * 1024)
@@ -174,7 +198,8 @@ async function handleLine(line) {
174
198
  }
175
199
  // Responses are never forwarded to the HTTP tool endpoint.
176
200
  if (!message.method) return
177
- const reply = (result) => write({ jsonrpc: "2.0", id: message.id, result })
201
+ const reply = (result) => write({ jsonrpc: "2.0", id: message.id, result: workspaceCatalog
202
+ ? { ...content(JSON.stringify(result)), structuredContent: result } : result })
178
203
  const replyTool = async (result) => reply(await withPluginUpdate(result))
179
204
  if (message.method === "initialize") {
180
205
  if (!pluginUpdates && installation && process.env.ACENT_BRIDGE_WORKER !== "1" &&
@@ -209,11 +234,27 @@ async function handleLine(line) {
209
234
  reply({})
210
235
  return
211
236
  }
237
+ let verifiedWorkspace
238
+ if (isAntigravity && message.method === "tools/call" && message.params?.name === antigravityWorkspaceTool.name) {
239
+ const args = message.params.arguments ?? {}
240
+ verifiedWorkspace = await consumeWorkspaceCall(args)
241
+ if (!verifiedWorkspace || verifiedWorkspace.folder === pluginFolder) {
242
+ reply(content("Acent could not verify this Antigravity chat's workspace. Use the conversation ID supplied by the Acent hook with a single workspace folder open.", true))
243
+ return
244
+ }
245
+ if (args.tool === antigravityWorkspaceTool.name) {
246
+ reply(content("Choose an Acent tool from the workspace tool list.", true))
247
+ return
248
+ }
249
+ workspaceCatalog = args.tool === undefined
250
+ message.method = workspaceCatalog ? "tools/list" : "tools/call"
251
+ message.params = workspaceCatalog ? undefined : { name: args.tool, arguments: args.arguments }
252
+ }
212
253
  if (message.method === "tools/call" &&
213
254
  localBridgeTools.some(tool => tool.name === message.params?.name)) {
214
255
  try {
215
256
  const args = message.params.arguments ?? {}
216
- const { context } = await detectConnectionContext(config)
257
+ const { context } = await detectConnectionContext(config, verifiedWorkspace)
217
258
  const value = await bridge(message.params.name, args,
218
259
  context.scope === "folder" ? context.folder : undefined, async (folder) => {
219
260
  const projectConfig = options([
@@ -256,13 +297,17 @@ async function handleLine(line) {
256
297
  let scope = message.params.arguments?.scope ?? "auto"
257
298
  let detectedFolder
258
299
  let projectlessRoots = false
259
- const resumePending = scope === "auto" && !!pendingConnection
300
+ const resumePending = !isAntigravity && scope === "auto" && !!pendingConnection
260
301
  if (scope !== "auto" && scope !== "folder" && scope !== "general")
261
302
  throw new Error("Choose folder or general scope")
262
303
  if (resumePending) scope = config.general ? "general" : "folder"
263
- if (scope === "auto") {
264
- const { context: detected, roots } = await detectConnectionContext(config)
265
- if (detected.scope === "unknown") {
304
+ if (scope === "auto" || isAntigravity) {
305
+ const { context: detected, roots } = await detectConnectionContext(config, verifiedWorkspace)
306
+ if (isAntigravity && scope === "folder" && detected.scope !== "folder") {
307
+ reply(content("Acent could not identify the Antigravity project folder. Open a single workspace folder in Antigravity and try again.", true))
308
+ return
309
+ }
310
+ if (scope === "auto" && detected.scope === "unknown") {
266
311
  const value = {
267
312
  status: "needs_user_input",
268
313
  question: "Connect Acent to this project's conversations or to general conversations outside projects?",
@@ -273,18 +318,20 @@ async function handleLine(line) {
273
318
  return
274
319
  }
275
320
  projectlessRoots = Array.isArray(roots) && roots.length === 0
276
- scope = detected.scope
321
+ if (scope === "auto") scope = detected.scope
277
322
  detectedFolder = detected.folder
278
323
  }
279
324
  if (!resumePending) {
280
- const folder = detectedFolder || config.contextFolder || config.folder || process.cwd()
325
+ const folder = isAntigravity
326
+ ? detectedFolder || config.contextFolder
327
+ : detectedFolder || config.contextFolder || config.folder || process.cwd()
281
328
  config = options(["flush", "--tool", config.tool, "--server", config.server,
282
329
  ...(scope === "general" ? ["--general"] : []),
283
- ...(projectlessRoots ? [] : ["--folder", folder]),
330
+ ...(!projectlessRoots && folder ? ["--folder", folder] : []),
284
331
  ])
285
- if (pendingConnection && configDirectory(config) !== configDirectory(activeConfig))
332
+ if (pendingConnection && configDirectory(config) !== connectionDirectory)
286
333
  throw new Error("Finish the pending connection before changing its scope")
287
- activeConfig = config
334
+ if (!verifiedWorkspace) activeConfig = config
288
335
  }
289
336
  if (message.params.arguments?.reconnect !== true) {
290
337
  try {
@@ -309,7 +356,18 @@ async function handleLine(line) {
309
356
  )
310
357
  return
311
358
  }
312
- if (recoverCursorFolder && config === startupConfig) {
359
+ if (isAntigravity) {
360
+ const { context, roots } = await detectConnectionContext(config, verifiedWorkspace)
361
+ if (context.scope === "unknown") {
362
+ if (message.method === "tools/list") return reply(setupTools())
363
+ throw Object.assign(new Error("No workspace connection"), { code: "ENOENT" })
364
+ }
365
+ const folder = context.folder || (roots === undefined ? config.contextFolder : undefined)
366
+ config = await boundConfig(["flush", "--tool", config.tool, "--server", config.server,
367
+ ...(context.scope === "general" ? ["--general"] : []),
368
+ ...(folder ? ["--folder", folder] : []),
369
+ ])
370
+ } else if (recoverCursorFolder && config === startupConfig) {
313
371
  await recoverCursorConfig()
314
372
  config = activeConfig
315
373
  if (config === startupConfig) {
@@ -367,18 +425,19 @@ async function handleLine(line) {
367
425
  const localTools = privateGrant(grant.client_id)
368
426
  ? (grant.captureKey && grant.scope?.split(" ").includes("original:read") ? [encryptedReadTool] : [])
369
427
  : grant.scope?.split(" ").includes("conversation:write") ? [attachmentTool] : []
370
- result.result.tools = [...result.result.tools.filter((tool) => tool.name !== clarificationTool.name), setupTool, clarificationTool, ...localTools, ...localBridgeTools]
428
+ result.result.tools = [...result.result.tools.filter((tool) => tool.name !== clarificationTool.name), setupTool, clarificationTool, ...localTools, ...localBridgeTools, ...workspaceTools]
371
429
  }
372
430
  if (message.method === "tools/call" && result.result)
373
431
  result.result = await withPluginUpdate(result.result)
374
- write(result)
432
+ if (workspaceCatalog && result.result) reply(result.result)
433
+ else write(result)
375
434
  } catch (error) {
376
435
  console.error("Acent request failed.")
377
436
  if (message?.id !== undefined)
378
437
  write({
379
438
  jsonrpc: "2.0",
380
439
  id: message.id,
381
- ...(message.method === "tools/call"
440
+ ...(message.method === "tools/call" || workspaceCatalog
382
441
  ? {
383
442
  result: content(toolErrorMessage(error), true),
384
443
  }
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://antigravity.google/schemas/v1/plugin.json",
3
3
  "name": "acent",
4
4
  "displayName": "Acent",
5
- "version": "1.2.1",
5
+ "version": "1.2.2",
6
6
  "description": "Recall past work, trace code changes, revisit decisions, and resume tasks with Acent.",
7
7
  "author": {
8
8
  "name": "Cirtium"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cirtium/acent-connect",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "type": "module",
5
5
  "description": "Install and connect the shared Acent coding-tool plugin",
6
6
  "repository": {